Kaynağa Gözat

Emoji analyse almost done and some work on changing the way you change settings using the bot.

tags/v1.3.0
roxie 6 yıl önce
ebeveyn
işleme
80cf553343
4 değiştirilmiş dosya ile 143 ekleme ve 118 silme
  1. +22
    -12
      cogs/admin.py
  2. +116
    -100
      cogs/settings.py
  3. +4
    -2
      cogs/util.py
  4. +1
    -4
      config/server_config.py

+ 22
- 12
cogs/admin.py Dosyayı Görüntüle

import datetime
import discord import discord
from discord.ext.commands import bot

import checks import checks
from discord.ext.commands import bot, group


class Admin(): class Admin():
""" """
@checks.is_owner_or_admin() @checks.is_owner_or_admin()
@bot.command(pass_context=True) @bot.command(pass_context=True)
async def emojiuse(self, ctx, emoji, *args): async def emojiuse(self, ctx, emoji, *args):
# TODO: Add check that emoji is an emoji
# Flag Parsing # Flag Parsing


if "-v" in args: if "-v" in args:
amount += channel amount += channel
return amount return amount


def use_by_day(amount):
useperday = amount / 30
useperday = "{0:.2f}".format(useperday)
return useperday


def verbose_output(usage): def verbose_output(usage):
output = "" output = ""
for channel in usage: for channel in usage:
for channel in ctx.message.server.channels: for channel in ctx.message.server.channels:
if channel.type == discord.ChannelType.text: # Only looks at server's text channels if channel.type == discord.ChannelType.text: # Only looks at server's text channels
x = 0 x = 0
async for message in self.bot.logs_from(channel, limit=20000):
async for message in self.bot.logs_from(channel, limit=1000000, after=datetime.datetime.now() + datetime.timedelta(-30)):
if str(emoji) in message.content: if str(emoji) in message.content:
x += 1 x += 1
usage[channel.id] = x usage[channel.id] = x


# Command # Command


await self.bot.say("Warning! This command may take upto 5 minutes to process. Please do no spam me. I am working.", delete_after=20)
await self.bot.say("Warning! This command may take upto 15 minutes to process. Please do no spam me. I am working.", delete_after=20)
await self.bot.send_typing(ctx.message.channel) await self.bot.send_typing(ctx.message.channel)


if all_emojis: if all_emojis:
for emoji in ctx.message.server.emojis: for emoji in ctx.message.server.emojis:
emoji_usage[emoji.id] = await count_uses() emoji_usage[emoji.id] = await count_uses()


em = discord.Embed()
em = discord.Embed(colour=0xDEADBF)
for emoji in emoji_usage: for emoji in emoji_usage:
emoji_obj = discord.utils.get(ctx.message.server.emojis, id=emoji) emoji_obj = discord.utils.get(ctx.message.server.emojis, id=emoji)
em.add_field(name=str(emoji_obj), value=sum(emoji_usage[emoji]))
return await self.bot.say(embed=em)
amount = sum(emoji_usage[emoji])
useperday = use_by_day(amount)
em.add_field(name=str(emoji_obj), value="Amount Used: {}\nUse/Day: {}".format(amount, useperday), inline=False)
return await self.bot.say(content="Below is a report of all custom emoji on this server and how many times they have been used in the previous 30 days. This includes a usage/day ratio.", embed=em)


else: else:
usage = await count_uses() usage = await count_uses()

amount = sum(usage)
useperday = use_by_day(amount)
if verbose: if verbose:
amount = sum(usage)
output = verbose_output(usage) output = verbose_output(usage)
output_em = discord.Embed(description = output)
return await self.bot.say(content = "{} has been used {} time(s). Here is the break down per channel.".format(emoji, amount), embed=output_em)
output_em = discord.Embed(description=output, colour=0xDEADBF)
return await self.bot.say(content="{} has been used {} time(s) in the last month. That's {}/day. Here is the break down per channel.".format(emoji, amount, useperday), embed=output_em)


else: # Non-verbose output else: # Non-verbose output
amount = sum(usage)
return await self.bot.say("{} has been used {} time(s) server wide.".format(emoji, amount))
return await self.bot.say("{} has been used {} time(s) in the last month. That's {}/day.".format(emoji, amount, useperday))







+ 116
- 100
cogs/settings.py Dosyayı Görüntüle

blacklist_amount += 1 blacklist_amount += 1
return await self.bot.say('{} user(s) have been removed from the blacklist'.format(blacklist_amount)) return await self.bot.say('{} user(s) have been removed from the blacklist'.format(blacklist_amount))


@bot.command(pass_context=True)
@checks.is_owner_or_admin()
async def enablesetting(self, ctx, setting):
"OWNER OR ADMIN ONLY: Enables settings in the server config."
self.serverconfig = self.con.load_config()
server_id = ctx.message.server.id
if setting in self.serverconfig[server_id]:
if not self.serverconfig[server_id][setting]["enabled"]:
self.serverconfig[server_id][setting]["enabled"] = 1
self.con.update_config(self.serverconfig)
return await self.bot.say("'{}' was enabled!".format(setting))
else:
self.serverconfig[server_id][setting]["enabled"] = 0
self.con.update_config(self.serverconfig)
return await self.bot.say("'{}' was disabled :cry:".format(setting))
@bot.command(pass_context=True, hidden=True, aliases=["setava", "setavatar"])
@checks.is_bot_owner()
async def changeavatar(self, ctx, url=None):
"""
Usage:
{command_prefix}setavatar [url]
Changes the bot's avatar.
Attaching a file and leaving the url parameter blank also works.
"""
if ctx.message.attachments:
thing = ctx.message.attachments[0]['url']
else: else:
return await self.bot.say("That module dont exist fam. You made the thing")
thing = url.strip('<>')

avaimg = 'avaimg'
async with aiohttp.ClientSession() as session:
async with session.get(thing) as img:
with open(avaimg, 'wb') as f:
f.write(await img.read())
with open(avaimg, 'rb') as f:
await self.bot.edit_profile(avatar=f.read())
os.remove(avaimg)
asyncio.sleep(2)
return await self.bot.say(":ok_hand:")

@bot.command(pass_context=True, hidden=True, aliases=["nick"])
@checks.is_bot_owner()
async def changenickname(self, ctx, *nick):
if ctx.message.channel.permissions_for(ctx.message.server.me).change_nickname:
await self.bot.change_nickname(ctx.message.server.me, ' '.join(nick))
return await self.bot.say(":thumbsup:")
else:
return await self.bot.say("I don't have permission to do that :sob:", delete_after=self.con.delete_after)

@bot.command(pass_context=True, hidden=True, aliases=["setgame", "game"])
@checks.is_bot_owner()
async def changegame(self, ctx, *, game: str):
if game.lower() == "none":
game_name = None
else:
game_name = discord.Game(name=game, type=0)
await self.bot.change_presence(game=game_name, afk=False)
return await self.bot.say(":ok_hand: Game set to {}".format(str(game_name)))

@bot.command(pass_context=True, hidden=True, aliases=["status"])
@checks.is_bot_owner()
async def changestatus(self, ctx, status: str):
status = status.lower()
if status == 'offline' or status == 'invisible':
discordStatus = discord.Status.invisible
elif status == 'idle':
discordStatus = discord.Status.idle
elif status == 'dnd':
discordStatus = discord.Status.dnd
else:
discordStatus = discord.Status.online
await self.bot.change_presence(status=discordStatus)
await self.bot.say("**:ok:** Status set to {}".format(discordStatus))

@bot.command(hidden=True)
@checks.is_bot_owner()
async def restart(self):
await self.bot.logout()
return os.execl(sys.executable, sys.executable, *sys.argv)

@bot.command(hidden=True)
@checks.is_bot_owner()
async def shutdown(self):
await self.bot.logout()
return exit(0)

@bot.command(pass_context=True, hidden=True)
@checks.is_bot_owner()
async def announce(self, ctx, *announcement):
"""
ONLY USE FOR SERIOUS ANNOUNCEMENTS
"""
# TODO: Make colour top level role colour
# TODO: Custom message for annoucement footer
embed = discord.Embed(title="RoxBot Announcement", colour=discord.Colour(0x306f99), description=' '.join(announcement))
embed.set_footer(text="This message has be automatically generated by a cute ass Roxie",
icon_url=self.bot.user.avatar_url)
for server in self.bot.servers:
await self.bot.send_message(server, embed=embed)
return await self.bot.say("Done!", delete_after=self.con.delete_after)


@bot.command(pass_context=True) @bot.command(pass_context=True)
@checks.is_owner_or_admin() @checks.is_owner_or_admin()


return await self.bot.say(embed=em) return await self.bot.say(embed=em)



@group(pass_context=True)
async def settings(self, ctx):
pass

@settings.command(pass_context=True)
async def self_assign(self, ctx, selection, *, changes = None):
if selection == "enable":
pass



@bot.command(pass_context=True)
@checks.is_owner_or_admin()
async def enablesetting(self, ctx, setting):
"OWNER OR ADMIN ONLY: Enables settings in the server config."
self.serverconfig = self.con.load_config()
server_id = ctx.message.server.id
if setting in self.serverconfig[server_id]:
if not self.serverconfig[server_id][setting]["enabled"]:
self.serverconfig[server_id][setting]["enabled"] = 1
self.con.update_config(self.serverconfig)
return await self.bot.say("'{}' was enabled!".format(setting))
else:
self.serverconfig[server_id][setting]["enabled"] = 0
self.con.update_config(self.serverconfig)
return await self.bot.say("'{}' was disabled :cry:".format(setting))
else:
return await self.bot.say("That module dont exist fam. You made the thing")



@group(pass_context=True, hidden=True) @group(pass_context=True, hidden=True)
@checks.is_bot_owner() @checks.is_bot_owner()
async def set(self, ctx): async def set(self, ctx):
self.con.update_config(self.servers) self.con.update_config(self.servers)
return await self.bot.say("'{}' has been removed from the Mod role list.".format(role.name)) return await self.bot.say("'{}' has been removed from the Mod role list.".format(role.name))


@bot.command(pass_context=True, hidden=True, aliases=["setava", "setavatar"])
@checks.is_bot_owner()
async def changeavatar(self, ctx, url=None):
"""
Usage:
{command_prefix}setavatar [url]
Changes the bot's avatar.
Attaching a file and leaving the url parameter blank also works.
"""
if ctx.message.attachments:
thing = ctx.message.attachments[0]['url']
else:
thing = url.strip('<>')

avaimg = 'avaimg'
async with aiohttp.ClientSession() as session:
async with session.get(thing) as img:
with open(avaimg, 'wb') as f:
f.write(await img.read())
with open(avaimg, 'rb') as f:
await self.bot.edit_profile(avatar=f.read())
os.remove(avaimg)
asyncio.sleep(2)
return await self.bot.say(":ok_hand:")


@bot.command(pass_context=True, hidden=True, aliases=["nick"])
@checks.is_bot_owner()
async def changenickname(self, ctx, *nick):
if ctx.message.channel.permissions_for(ctx.message.server.me).change_nickname:
await self.bot.change_nickname(ctx.message.server.me, ' '.join(nick))
return await self.bot.say(":thumbsup:")
else:
return await self.bot.say("I don't have permission to do that :sob:", delete_after=self.con.delete_after)

@bot.command(pass_context=True, hidden=True, aliases=["setgame", "game"])
@checks.is_bot_owner()
async def changegame(self, ctx, *, game: str):
if game.lower() == "none":
game_name = None
else:
game_name = discord.Game(name=game, type=0)
await self.bot.change_presence(game=game_name, afk=False)
return await self.bot.say(":ok_hand: Game set to {}".format(str(game_name)))

@bot.command(pass_context=True, hidden=True, aliases=["status"])
@checks.is_bot_owner()
async def changestatus(self, ctx, status: str):
status = status.lower()
if status == 'offline' or status == 'invisible':
discordStatus = discord.Status.invisible
elif status == 'idle':
discordStatus = discord.Status.idle
elif status == 'dnd':
discordStatus = discord.Status.dnd
else:
discordStatus = discord.Status.online
await self.bot.change_presence(status=discordStatus)
await self.bot.say("**:ok:** Status set to {}".format(discordStatus))

@bot.command(hidden=True)
@checks.is_bot_owner()
async def restart(self):
await self.bot.logout()
return os.execl(sys.executable, sys.executable, *sys.argv)

@bot.command(hidden=True)
@checks.is_bot_owner()
async def shutdown(self):
await self.bot.logout()
return exit(0)

@bot.command(pass_context=True, hidden=True)
@checks.is_bot_owner()
async def announce(self, ctx, *announcement):
"""
ONLY USE FOR SERIOUS ANNOUNCEMENTS
"""
# TODO: Make colour top level role colour
# TODO: Custom message for annoucement footer
embed = discord.Embed(title="RoxBot Announcement", colour=discord.Colour(0x306f99), description=' '.join(announcement))
embed.set_footer(text="This message has be automatically generated by a cute ass Roxie",
icon_url=self.bot.user.avatar_url)
for server in self.bot.servers:
await self.bot.send_message(server, embed=embed)
return await self.bot.say("Done!", delete_after=self.con.delete_after)




def setup(Bot): def setup(Bot):

+ 4
- 2
cogs/util.py Dosyayı Görüntüle

@bot.command(pass_context=True, hidden=True) @bot.command(pass_context=True, hidden=True)
@checks.is_bot_owner() @checks.is_bot_owner()
async def echo(self, ctx, channel, *, message: str): async def echo(self, ctx, channel, *, message: str):
if ctx.message.channel_mentions:
if ctx.message.channel_mentions: # If Mentioned
for channel in ctx.message.channel_mentions: for channel in ctx.message.channel_mentions:
await self.bot.send_message(channel, content=message) await self.bot.send_message(channel, content=message)
return await self.bot.say(":point_left:") return await self.bot.say(":point_left:")
elif channel.isdigit():

elif channel.isdigit(): # If ID is given
channel = ctx.message.server.get_channel(channel) channel = ctx.message.server.get_channel(channel)
await self.bot.send_message(channel, content=message) await self.bot.send_message(channel, content=message)
return await self.bot.say(":point_left:") return await self.bot.say(":point_left:")

else: else:
return await self.bot.say("You did something wrong smh") return await self.bot.say("You did something wrong smh")



+ 1
- 4
config/server_config.py Dosyayı Görüntüle

"whitelist": { "whitelist": {
"enabled": 0, "enabled": 0,
"list": [] "list": []
},
},
"mute": {
"role": ""
}
}, },
"nsfw": { "nsfw": {
"enabled": 0, "enabled": 0,

Yükleniyor…
İptal
Kaydet