import discord import file_utils as f import dict_writer as writer import random TOKEN = f.readToken() client = discord.Client() noreply = [] noreply = f.readBlacklist() pre = "!" stats = writer.dict_writer(file = "usage_stats.txt") stats.generate_file() def msgStartsWith(message, str): return message.content.lower().startswith(str) #this code is so bad @client.event async def on_message(message): channel = message.channel # Make sure the bot doesn't reply to itself if message.author == client.user: return # Essentially ping, without the time measurement: pre + "hello" if msgStartsWith(message, pre + 'hello'): await channel.send('Hey {0.author.mention}'.format(message)) # Replies with the amount of times the user has been dad'ed if msgStartsWith(message, pre + 'stats'): author_stats = stats.get_value(str(message.author.id)) if author_stats == -1: author_stats = 0 await channel.send("You've been dad'ed "+str(author_stats)+" times!") # Reply with the user's UUID if msgStartsWith(message, pre + 'id'): await channel.send("Your UUID is: " + str(message.author.id)) # Adds/removes users from the blacklist: pre + "noreply" if msgStartsWith(message, pre + 'noreply'): if message.author.id in noreply: noreply.remove(message.author.id) f.updateBlacklist(noreply) await channel.send("You have been successfully removed from the blacklist") else: noreply.append(message.author.id) f.updateBlacklist(noreply) await channel.send("You have been added to the blacklist") # Prints the current blacklist: pre + "blacklist" if msgStartsWith(message, pre + 'blacklist'): blacklist = [] for i in noreply: user = await client.fetch_user(i) blacklist.append(str(user.display_name)) msg = "Currently blacklisted users are: " + ", ".join(blacklist) await channel.send(msg) # Prints the help menu: pre + "help" if msgStartsWith(message, pre + 'help'): msg = ("Hey, {0.author.mention} here's my list of commands.\n".format(message) + pre +'hello - Says hello back and pings you\n' + pre +'noreply - Toggles dad joke opportunity detection for you\n' + pre +"stats - Shows how many times you've been dad'ed\n" + pre +'help - Displays this menu\n' + pre +'blacklist - Lists the currently ignored users\n' + pre +'ID - Replies with your UUID\n' + '**HERA** v1.00') await channel.send(msg) #I’m # or ( ord(msg.lower()[0]) == 105 and (ord(msg.lower()[1]) == 39 or ord(msg.lower()[1]) == 8217) and ord(msg.lower()[2]) == 109) if msgStartsWith(message, "im ") or msgStartsWith(message, "me ") or ( ord(message.content.lower()[0]) == 105 and (ord(message.content.lower()[1]) == 39 or ord(message.content.lower()[1]) == 8217) and ord(message.content.lower()[2]) == 109 and message.content.lower()[3] == " "): if message.author.id in noreply: return msg = message.content if len(msg.split()) < 2: return msg = msg[msg.find(" ") + 1:] if len(msg.split()) == 1: if msg[-1] == ".": msg = msg[0:len(msg)-1] if len(msg) == 1 and not 97 <= ord(msg.lower()) <= 122: return elif len(msg.split()) >= 2: splitIndex = max([msg.find("."), msg.find(",")]) if splitIndex == -1: splitIndex = len(msg) msg = msg[:splitIndex] if msg == "": return msg = msg.replace("\n", "") await channel.send("Hi "+msg+", I'm Hera") author_stats = int(stats.get_value(str(message.author.id))) if author_stats == -1: stats.update_value({str(message.author.id): 1}) else: stats.update_value({str(message.author.id): author_stats + 1}) #creator only commands if message.author.id == 243885191527923723: if msgStartsWith(message, pre + 'stop'): await channel.send("Going offline...") await client.logout() @client.event async def on_ready(): print('Logged in as') print(client.user.name) print(client.user.id) print('------') game = discord.Game("Now with stats!") await client.change_presence(status=discord.Status.idle, activity=game) client.run(TOKEN)