|
@@ -0,0 +1,99 @@
|
|
|
+import json
|
|
|
+import sys
|
|
|
+import logging
|
|
|
+import discord
|
|
|
+from config import Config
|
|
|
+from logger import logger
|
|
|
+from db import MarketDB
|
|
|
+
|
|
|
+TOKEN = Config["Tokens"]["BoobyLegendsEcon"]["Token"]
|
|
|
+
|
|
|
+def parse(input,author):
|
|
|
+ # parse the input string from the message so that we can see what we need to do
|
|
|
+ parts = input.strip().split()
|
|
|
+ logger.debug(input)
|
|
|
+ logger.debug(parts)
|
|
|
+
|
|
|
+ #global decoder
|
|
|
+
|
|
|
+ AuthorName = author
|
|
|
+
|
|
|
+ #drop out if this is not a Roll command
|
|
|
+ if len(parts) == 0:
|
|
|
+ return None
|
|
|
+ if parts[0].upper() not in ['!','/','\\']:
|
|
|
+ #Try to make a command if first character is !
|
|
|
+ if parts[0][0]=="!":
|
|
|
+ pt=["!",parts[0][1:]]
|
|
|
+ pt.extend(parts[1:])
|
|
|
+ parts=pt
|
|
|
+ logger.debug(parts)
|
|
|
+ else:
|
|
|
+ logger.debug("Not a command")
|
|
|
+ return None
|
|
|
+
|
|
|
+ try:
|
|
|
+ logger.debug("Command: "+parts[1].upper())
|
|
|
+ if parts[1].upper() == "HISTORY":
|
|
|
+ name = ' '.join(parts[2:])
|
|
|
+ logger.info("History for: "+name)
|
|
|
+ history=""
|
|
|
+ #give user message so he knows it's saved
|
|
|
+ retstr = "{Author} requested history for {name}:\n{history}".format(
|
|
|
+ Author=author,
|
|
|
+ name=name,
|
|
|
+ history=history
|
|
|
+ )
|
|
|
+ logger.debug(retstr)
|
|
|
+ elif parts[1].upper() == "TODAY":
|
|
|
+ logger.info("Today")
|
|
|
+ retstr = ""
|
|
|
+ elif parts[1].upper() in ["LOGLEVEL"]:
|
|
|
+ if parts[2].upper() == "DEBUG":
|
|
|
+ logger.setLevel(logging.DEBUG)
|
|
|
+ elif parts[2].upper() == "INFO":
|
|
|
+ logger.setLevel(logging.INFO)
|
|
|
+ retstr= "LogLevel set to "+parts[2].upper()
|
|
|
+ elif parts[1].upper() in ["HELP"]:
|
|
|
+ retstr = '''
|
|
|
+My Key words are "!", "/", or "\\"
|
|
|
+Show a Card's Historical cost with:```!History Eva Elfie```
|
|
|
+Show the current day's average prices with:```!Today```
|
|
|
+'''
|
|
|
+ else:
|
|
|
+ retstr = '{Author}, your command was not understood.'.format(Author=author)
|
|
|
+ except Exception as e:
|
|
|
+ print(e)
|
|
|
+ retstr = None
|
|
|
+
|
|
|
+ return retstr
|
|
|
+
|
|
|
+
|
|
|
+#########################################################################
|
|
|
+# Main Program
|
|
|
+#########################################################################
|
|
|
+
|
|
|
+intents = discord.Intents.default()
|
|
|
+intents.message_content = True
|
|
|
+
|
|
|
+client = discord.Client(intents=intents)
|
|
|
+
|
|
|
+# This block is the work horse part
|
|
|
[email protected]
|
|
|
+async def on_message(message):
|
|
|
+ # we do not want the bot to reply to itself
|
|
|
+ if message.author == client.user:
|
|
|
+ return
|
|
|
+ # get the output for the given message
|
|
|
+ output = parse(message.content,message.author.display_name)
|
|
|
+ if output is not None:
|
|
|
+ await message.channel.send(output)
|
|
|
+
|
|
|
[email protected]
|
|
|
+async def on_ready():
|
|
|
+ print('Logged in as')
|
|
|
+ print(client.user.name)
|
|
|
+ print(client.user.id)
|
|
|
+ print('------')
|
|
|
+
|
|
|
+client.run(TOKEN)
|