SHARE
TWEET

HERA.py

a guest Oct 21st, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import discord
  2. import file_utils as f
  3. import dict_writer as writer
  4. import random
  5.  
  6. TOKEN = f.readToken()
  7. client = discord.Client()
  8. noreply = []
  9. noreply = f.readBlacklist()
  10. pre = "!"
  11. stats = writer.dict_writer(file = "usage_stats.txt")
  12. stats.generate_file()
  13. def msgStartsWith(message, str): return message.content.lower().startswith(str)
  14.  
  15. #this code is so bad
  16. @client.event
  17. async def on_message(message):
  18.     channel = message.channel
  19.  
  20.     # Make sure the bot doesn't reply to itself
  21.     if message.author == client.user:
  22.         return
  23.  
  24.     # Essentially ping, without the time measurement: pre + "hello"
  25.     if msgStartsWith(message, pre + 'hello'): await channel.send('Hey {0.author.mention}'.format(message))
  26.  
  27.     # Replies with the amount of times the user has been dad'ed
  28.     if msgStartsWith(message, pre + 'stats'):
  29.         author_stats = stats.get_value(str(message.author.id))
  30.         if author_stats == -1: author_stats = 0
  31.         await channel.send("You've been dad'ed "+str(author_stats)+" times!")
  32.  
  33.     # Reply with the user's UUID
  34.     if msgStartsWith(message, pre + 'id'): await channel.send("Your UUID is: " + str(message.author.id))
  35.  
  36.     # Adds/removes users from the blacklist: pre + "noreply"
  37.     if msgStartsWith(message, pre + 'noreply'):
  38.         if message.author.id in noreply:
  39.             noreply.remove(message.author.id)
  40.             f.updateBlacklist(noreply)
  41.             await channel.send("You have been successfully removed from the blacklist")
  42.         else:
  43.             noreply.append(message.author.id)
  44.             f.updateBlacklist(noreply)
  45.             await channel.send("You have been added to the blacklist")
  46.  
  47.     # Prints the current blacklist: pre + "blacklist"
  48.     if msgStartsWith(message, pre + 'blacklist'):
  49.         blacklist = []
  50.         for i in noreply:
  51.             user = await client.fetch_user(i)
  52.             blacklist.append(str(user.display_name))
  53.         msg = "Currently blacklisted users are: " + ", ".join(blacklist)
  54.         await channel.send(msg)
  55.  
  56.     # Prints the help menu: pre + "help"
  57.     if  msgStartsWith(message, pre + 'help'):
  58.         msg = ("Hey, {0.author.mention} here's my list of commands.\n".format(message) +
  59.         pre +'hello - Says hello back and pings you\n' +
  60.         pre +'noreply - Toggles dad joke opportunity detection for you\n' +
  61.         pre +"stats - Shows how many times you've been dad'ed\n" +
  62.         pre +'help - Displays this menu\n' +
  63.         pre +'blacklist - Lists the currently ignored users\n' +
  64.         pre +'ID - Replies with your UUID\n' +
  65.         '**HERA** v1.00')
  66.         await channel.send(msg)
  67.  
  68.     #I’m
  69.     # or ( ord(msg.lower()[0]) == 105 and (ord(msg.lower()[1]) == 39 or ord(msg.lower()[1]) == 8217) and ord(msg.lower()[2]) == 109)
  70.     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] == " "):
  71.         if message.author.id in noreply: return
  72.         msg = message.content
  73.         if len(msg.split()) < 2: return
  74.         msg = msg[msg.find(" ") + 1:]
  75.         if len(msg.split()) == 1:
  76.             if msg[-1] == ".":
  77.                 msg = msg[0:len(msg)-1]
  78.             if len(msg) == 1 and not 97 <= ord(msg.lower()) <= 122: return
  79.         elif len(msg.split()) >= 2:
  80.             splitIndex = max([msg.find("."), msg.find(",")])
  81.             if splitIndex == -1: splitIndex = len(msg)
  82.             msg = msg[:splitIndex]
  83.         if msg == "": return
  84.         msg = msg.replace("\n", "")
  85.         await channel.send("Hi "+msg+", I'm Hera")
  86.         author_stats = int(stats.get_value(str(message.author.id)))
  87.         if author_stats == -1: stats.update_value({str(message.author.id): 1})
  88.         else: stats.update_value({str(message.author.id): author_stats + 1})
  89.  
  90.  
  91.     #creator only commands
  92.     if message.author.id == 243885191527923723:
  93.         if msgStartsWith(message, pre + 'stop'):
  94.             await channel.send("Going offline...")
  95.             await client.logout()
  96.  
  97. @client.event
  98. async def on_ready():
  99.     print('Logged in as')
  100.     print(client.user.name)
  101.     print(client.user.id)
  102.     print('------')
  103.     game = discord.Game("Now with stats!")
  104.     await client.change_presence(status=discord.Status.idle, activity=game)
  105.  
  106. client.run(TOKEN)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top