Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import config
- bot = config.bot
- TLnotes = dict()
- # TLnotes can be hardcoded following the example below, or temporarily added via !tlnote & stored via !save
- TLnotes["sasuga"] = "epic"
- try:
- with open('TLnotes.txt','r') as inf:
- TLnotes = eval(inf.read())
- except:
- print("Could not load TLnotes.txt, try adding some")
- @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
- async def on_message(ctx): # Listens for message to help translate
- if ctx.author == bot.user:
- return
- for x in TLnotes:
- if x.lower() in ctx.content.lower(): # Remove .lower if TLnotes should be case sensitive
- await ctx.send(f"> (tlnote: __{x.capitalize()}__ means *{TLnotes[x]}*)")
- print(f"{ctx.author} Requested tlnote")
- @bot.command()
- async def tlnote(ctx, *, arg):
- if ctx.author == bot.user:
- return
- print(f"{ctx.author} Added tlnote: {arg}")
- content = arg.split(" = ")
- TLnotes.update({content[0] : content[1]})
- await ctx.send("translators note temporarily added! Ask your local Discord priest to !tlsave")
- @bot.command()
- async def tlsave(ctx): # Saves any added tlnotes for future sessions
- if ctx.author == bot.user:
- return
- if ctx.author.id in config.admins:
- print(f"{ctx.author} Updated tlnotes.txt: ")
- await ctx.send("New Tlnote saved.")
- with open("TLnotes.txt", "w") as f:
- print(TLnotes, file=f)
- else:
- await bot.send("```cs\n # UNAUTHORIZED ACCESS DETECTED, ACTIVATING WEAPON SYSTEMS #\n```")
- @bot.command()
- async def tldelete(ctx, arg): # Deletes tlnote
- if ctx.author == bot.user:
- return
- print(f"{ctx.author} Deleting from tlnotes")
- if ctx.author.id in config.admins:
- try:
- print("Deleted from tlnotes: ", arg, "-", TLnotes[arg])
- del TLnotes[arg]
- await ctx.send("Removed translators note, for now")
- # Uncomment to save tlnotes to file when delete command is ran
- # with open("TLnotes.txt", "w") as f:
- # print(TLnotes, file=f)
- except:
- await ctx.send("Can't delete what's not there ¯\_(ツ)_/¯")
- else:
- await ctx.send("```cs\n # UNAUTHORIZED ACCESS DETECTED, ACTIVATING WEAPON SYSTEMS #\n```")
- @tlnote.error # Error handling
- async def tlnote_error(error, ctx):
- print(f"{ctx.message.author} Requested tlnote: {error}")
- 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