diff --git a/.gitignore b/.gitignore index 794b346..4d1b492 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,10 @@ # API-Key (keep secret at all times) key.py + +# Cookies +.google-cookie + + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/.google-cookie b/.google-cookie deleted file mode 100644 index 586e867..0000000 --- a/.google-cookie +++ /dev/null @@ -1,5 +0,0 @@ -#LWP-Cookies-2.0 -Set-Cookie3: 1P_JAR="2020-05-14-16"; path="/"; domain=".google.com"; path_spec; domain_dot; secure; expires="2020-06-13 16:24:54Z"; version=0 -Set-Cookie3: NID="204=n_wUpdR_TRFItRjyHxZ36B0EybjpBvLOa2ZsmpYnFPdVyLkmIaHc86rv9Ne06Ky5XEPRNNnsIHNzfmZc0NVnCf3HujqVbmYxN9OocwqASX0dYmH4B8Iy9UdLmvAUUfKC5FB3EkMMi_Q491lUiFSSbznjktAAMgcuHvJ7MBFAC7w"; path="/"; domain=".google.com"; path_spec; domain_dot; expires="2020-11-12 15:07:25Z"; HttpOnly=None; version=0 -Set-Cookie3: CGIC=""; path="/complete/search"; domain=".google.com"; path_spec; domain_dot; expires="2020-11-09 15:07:25Z"; HttpOnly=None; version=0 -Set-Cookie3: CGIC=""; path="/search"; domain=".google.com"; path_spec; domain_dot; expires="2020-11-09 15:07:25Z"; HttpOnly=None; version=0 diff --git a/README.md b/README.md index a6db6b3..04db60e 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ # chat-bot -Chat bot for two +Chat bot for two. diff --git a/main.py b/main.py index e5c65bd..0014bb5 100644 --- a/main.py +++ b/main.py @@ -7,23 +7,25 @@ import json import datetime import googlesearch import emoji +import Levenshtein as lev + from persistence import PersistentVars class ChatBot(): - def __init__(self, name, api_key, version): + def __init__(self, name, version): """Inits the Bot with a few conf. vars Args: -> name:str - Name of the bot -> api_key:str - t.me api-key -> version:str - Version number """ - self.base_url = "https://api.telegram.org/bot" + api_key + "/" + self.base_url = "https://api.telegram.org/bot" + key.telegram_api + "/" self.version = version self.name = name - # Persisten variable + # Persistent variable self.persistence = PersistentVars("permanent_vars.json") # Uptime counter @@ -162,11 +164,31 @@ class ChatBot(): /[command] [argument 1] [argument 2] ... """ full = command.split(" ") - if full[0] in self.commands: - self.commands[full[0]](full[1:]) + command = self.fuzzy_match_command(full[0]) + if len(command) != 1: + if command[0] == "EXACT": + self.commands[command[1]](full[1:]) + else: + send = "Did you mean " + command[1] + "" + for i in range(2,len(command)): + send += " or " + command[1] + "" + send += "?" + self.send_message(send) else: self.send_message("Command " + full[0] + " not found. Please try again.") + + def fuzzy_match_command(self, input): + matches = ["not exact"] + for command in self.commands.keys(): + if lev.ratio(input.lower(),command) > 0.8: + matches.append(command) + if lev.ratio(input.lower(),command) == 1: + return ["EXACT", command] + + return matches + + def send_thinking_note(self): data = { "chat_id" : self.chat_id, @@ -178,6 +200,7 @@ class ChatBot(): except: print("Could not show that I'm thinking =(") + def send_message(self, message): print("SENDING: " + emoji.demojize(message)) @@ -223,9 +246,11 @@ class ChatBot(): def bot_print_status(self, params): """Prints the bots current status and relevant information""" delta = str(datetime.datetime.now() - self.start_time) + ip = requests.get('https://api.ipify.org').text message = "
Status: Running :green_circle:\n"
-        message += "Uptime: " + delta + "\n"
+        message += "Uptime: " + delta[:delta.rfind(".")] + "\n"
         message += "Reboots: " + str(self.persistence.read("reboots")) + "\n"
+        message += "IP-Adress: " + ip + "\n"
         message += "Messages read: " + str(self.persistence.read("message_read")) + "\n"
         message += "Messages sent: " + str(self.persistence.read("message_sent")) + "
" self.send_message(message) @@ -325,9 +350,10 @@ class ChatBot(): def bot_show_help(self, params): """Shows a list of all commands and their description""" - send_text = "Hello, this is " + self.name + ", V." + self.version + "\n" - send_text += "Here is a list of the available commands:\n" - for entry in self.commands: + send_text = "BeebBop, this is " + self.name + " (V." + self.version + ")\n" + send_text += "Here is what I can do up to now: \n" + entries = sorted(list(self.commands.keys())) + for entry in entries: send_text += "" + entry + " - " send_text += "" + self.commands[entry].__doc__ + "\n\n" self.send_message(send_text) @@ -371,9 +397,9 @@ class ChatBot(): def bot_do_all(self,params): """Executes every single command with random params""" - for key in self.commands: - if key != "bot_do_all": - self.commands[key](["en","Freiburg"]) + for command in self.commands: + if command != "bot_do_all": + self.commands[command](["en","Freiburg"]) @@ -418,4 +444,4 @@ class ChatBot(): ####################################################################### -bot = ChatBot("ChatterBot", key.telegram_api, version="1.02") +bot = ChatBot("ChatterBot", version="1.03") diff --git a/permanent_vars.json b/permanent_vars.json index 8e83460..40a36ff 100644 --- a/permanent_vars.json +++ b/permanent_vars.json @@ -1 +1 @@ -{"message_read": 0, "message_sent": 0, "log": [], "chat_members": {}, "reboots": 0} +{"message_read": 27, "message_sent": 17, "log": [], "chat_members": {"364520272": "Remy Moll"}, "reboots": 20} \ No newline at end of file