-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
77 lines (68 loc) · 2.72 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import abc
import discord
from datetime import datetime
from discord.ext import commands
from discord import activity
from discord.ext.commands.core import has_permissions
from dataIO import fileIO
# check for settings file, create if missing
def check_settings():
if not fileIO("settings.json", "check"):
content = {
"TOKEN" : None}
print("settings.json missing, creating...")
fileIO("settings.json", "save", content)
# load settings file
check_settings()
settings = fileIO("settings.json" , "load")
token = settings["TOKEN"]
# hardcoded values (needed mainly for cogs)
presence = "v1.0 | @ me"
# check for missing variables
if token == None:
token = str(input("Please paste in your bot's token and hit enter. \n"))
settings["TOKEN"] = token
fileIO("settings.json" , "save", settings)
# finishing touches
bot = commands.Bot(command_prefix=commands.when_mentioned_or("em!"), help_command=None)
def timestamp():
dt = datetime.now()
ts = dt.strftime("%H:%M:%S")
return ts
# startup
@bot.event
async def on_ready():
user = str(bot.user)
guilds = len(bot.guilds)
print(" ")
print("{} ### Bot online!".format(timestamp()))
print("{} ### Bot username: {}".format(timestamp(), user))
print("{} ### Default prefix: {}".format(timestamp(), "em!"))
print("{} ### Currently in {} guilds".format(timestamp(), guilds))
print(" ")
# streaming status requires a twitch URL so we're redirecting the "Watch Stream" button to twitch's directory page
await bot.change_presence(status=discord.Status.online, activity=discord.Streaming(name=presence, url="https://www.twitch.tv/directory", twitch_name="directory"))
# commands
@bot.command(aliases = ['run'])
@commands.has_permissions(manage_messages=True)
@commands.guild_only()
async def genmessage(ctx):
"""Generates the emote list message and sends it in the current channel"""
emotes = []
counter = 0
# search all emojis in the guild and append to emotes list
for x in ctx.guild.emojis:
# formatting as follows: emote `:emote name: \n`
data = "{} `{}`".format(str(x), x.name)
emotes.append(data)
counter += 1
# put all emotes into string format and
msg = "\n".join(emotes)
left = ctx.guild.emoji_limit - counter
await ctx.message.delete()
# check for previous messages and delete previously generated lists
async for message in ctx.channel.history(limit=500): # limiting to 500 for better performance
if message.author.id == bot.user.id: # checking IDs should be faster
await message.delete()
await ctx.send("{}\n\n{}/{} emotes used ({} left)".format(msg, counter, ctx.guild.emoji_limit, left))
bot.run(token)