Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.62 KB | None | 0 0
  1. import config
  2. bot = config.bot
  3.  
  4. TLnotes = dict()
  5. # TLnotes can be hardcoded following the example below, or temporarily added via !tlnote & stored via !save
  6. TLnotes["sasuga"] = "epic"
  7.  
  8. try:
  9.     with open('TLnotes.txt','r') as inf:
  10.         TLnotes = eval(inf.read())
  11. except:
  12.     print("Could not load TLnotes.txt, try adding some")
  13.  
  14. @bot.listen()# could also change  to client event can also stay as bot.listen bot is a child of client and has all the effects of it
  15. async def on_message(ctx): # Listens for message to help translate
  16.     if ctx.author == bot.user:
  17.         return
  18.     for x in TLnotes:
  19.         if x.lower() in ctx.content.lower(): # Remove .lower if TLnotes should be case sensitive
  20.             await ctx.send(f"> (tlnote: __{x.capitalize()}__ means *{TLnotes[x]}*)")
  21.             print(f"{ctx.author} Requested tlnote")
  22.  
  23. @bot.command()
  24. async def tlnote(ctx, *, arg):
  25.     if ctx.author == bot.user:
  26.         return
  27.     print(f"{ctx.author} Added tlnote: {arg}")
  28.     content = arg.split(" = ")
  29.     TLnotes.update({content[0] : content[1]})
  30.     await ctx.send("translators note temporarily added! Ask your local Discord priest to !tlsave")
  31.  
  32. @bot.command()
  33. async def tlsave(ctx): # Saves any added tlnotes for future sessions
  34.     if ctx.author == bot.user:
  35.         return
  36.     if ctx.author.id in config.admins:
  37.         print(f"{ctx.author} Updated tlnotes.txt: ")
  38.         await ctx.send("New Tlnote saved.")
  39.         with open("TLnotes.txt", "w") as f:
  40.             print(TLnotes, file=f)
  41.     else:
  42.         await bot.send("```cs\n # UNAUTHORIZED ACCESS DETECTED, ACTIVATING WEAPON SYSTEMS #\n```")
  43.  
  44. @bot.command()
  45. async def tldelete(ctx, arg): # Deletes tlnote
  46.     if ctx.author == bot.user:
  47.         return
  48.     print(f"{ctx.author} Deleting from tlnotes")
  49.     if ctx.author.id in config.admins:
  50.         try:
  51.             print("Deleted from tlnotes: ", arg, "-", TLnotes[arg])
  52.             del TLnotes[arg]
  53.             await ctx.send("Removed translators note, for now")
  54.              # Uncomment to save tlnotes to file when delete command is ran
  55. #            with open("TLnotes.txt", "w") as f:
  56. #                print(TLnotes, file=f)
  57.         except:
  58.             await ctx.send("Can't delete what's not there ¯\_(ツ)_/¯")
  59.            
  60.     else:
  61.         await ctx.send("```cs\n # UNAUTHORIZED ACCESS DETECTED, ACTIVATING WEAPON SYSTEMS #\n```")
  62.  
  63. @tlnote.error # Error handling
  64. async def tlnote_error(error, ctx):
  65.     print(f"{ctx.message.author} Requested tlnote: {error}")
  66.     await ctx.send("Correct way to add translators notes: \n!tlnote _[trigger words]_  =  _[translation]_\n ex: `!tlnote sasuga = epic`")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement