Created
March 13, 2018 11:36
-
-
Save Roxxers/16a4b2449092f984d34dd94c031a3046 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@checks.is_admin_or_mod() | |
@bot.command(pass_context=True, enabled=False) | |
async def emojiuse(self, ctx, emoji, *args): | |
# TODO: Add check that emoji is an emoji | |
# TODO: Disable so like when we go to 1.3 this isn't live cause it needs more work and it needs to be completed already | |
# The way forward is clearly put the given emoji in and treat it as a list of emojis, | |
# if all emojis, then generate the list. Allows for more than one emoji to be analysed. Works better for larger servers/ | |
# Flag Parsing | |
if "-v" in args: | |
verbose = True | |
else: | |
verbose = False | |
if "-w" in args or emoji == "-w": # Second check just in case user just puts ";emojiuse -w" | |
all_emojis = True | |
else: | |
all_emojis = False | |
# Functions | |
def sum(usage): | |
amount = 0 | |
for channel in usage.values(): | |
amount += channel | |
return amount | |
def use_by_day(amount): | |
useperday = amount / 30 | |
useperday = "{0:.2f}".format(useperday) | |
return useperday | |
def verbose_output(usage): | |
output = "" | |
for channel in usage: | |
channel = self.bot.get_channel(channel) # Convert channel from ID to channel object to get name | |
output = output + "{}: {} \n".format(channel.name, usage[channel.id]) | |
return output | |
async def count_uses(): | |
usage = {} | |
for channel in ctx.message.server.channels: | |
if channel.type == discord.ChannelType.text: # Only looks at server's text channels | |
x = 0 | |
async for message in self.bot.logs_from(channel, limit=1000000, after=datetime.datetime.now() + datetime.timedelta(-30)): | |
if str(emoji) in message.content: | |
x += 1 | |
usage[channel.id] = x | |
print(str(emoji) + "HAS {} AMOUNT OF USES IN {}".format(x, str(channel))) | |
else: | |
pass | |
print("EMOJI WAS USED {} TOTAL TIMES".format(sum(usage))) | |
return usage | |
async def count_all_emoji(): | |
whitelist = [":yeetpride:",":yeet:", ":transgendercat:", ":thonkspin:", ":thonkegg:", ":ThinkPride:", ":thinkinggaysounds:", ":thatsgoodnews", ":pansexualcat:", ":nonbinarycat: ", ":kappa:", ":icantputpunctuationinemojinames:", ":hellothere:", ":agendercat:", ":Hedgeok:", ":extremethink:", ":donttryit:", ":cutie:", ":catappa:", ":boots:", ":awoo:", ":anotherhappylanding:", ":angrygay:"] | |
usage = {} | |
for emote in ctx.message.server.emojis: | |
name = ":{}:".format(emote.name) | |
if name in whitelist: | |
usage[emote.id] = 0 | |
for channel in ctx.message.server.channels: # TODO: ADD COUNTING BY CHANNEL | |
if channel.type == discord.ChannelType.text: # Only looks at server's text channels | |
async for message in self.bot.logs_from(channel, limit=1000000, after=datetime.datetime.now() + datetime.timedelta(-30)): | |
for emote in ctx.message.server.emojis: | |
if str(emote) in message.content and ":{}:".format(emote.name) in whitelist: | |
usage[emote.id] += 1 | |
print("{} found in message {}".format(str(emote), message.id)) | |
return usage | |
# Command | |
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) | |
if all_emojis: | |
emoji_usage = await count_all_emoji() | |
em = discord.Embed(colour=0xDEADBF) | |
for emoji in emoji_usage: | |
emoji_obj = discord.utils.get(ctx.message.server.emojis, id=emoji) | |
amount = 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: | |
usage = await count_uses() | |
amount = sum(usage) | |
useperday = use_by_day(amount) | |
if verbose: | |
output = verbose_output(usage) | |
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 | |
return await self.bot.say("{} has been used {} time(s) in the last month. That's {}/day.".format(emoji, amount, useperday)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment