From 2b23b120dc5fc64e1a323f3cc9fbbb8db57f69e2 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Tue, 19 Nov 2019 17:19:23 -0500 Subject: [PATCH 1/9] Add example robot --- documentation/setting up a new jail.md | 6 ++++ robots/auto_joe.json | 3 ++ robots/auto_joe.py | 41 ++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 documentation/setting up a new jail.md create mode 100644 robots/auto_joe.json create mode 100644 robots/auto_joe.py diff --git a/documentation/setting up a new jail.md b/documentation/setting up a new jail.md new file mode 100644 index 0000000..5ae77bb --- /dev/null +++ b/documentation/setting up a new jail.md @@ -0,0 +1,6 @@ +https://blog.pm2.io/2018-09-19/Manage-Python-Processes/ +https://www.npmjs.com/package/pm2 + +pm2 is super useful so install it + +use the first part of this guide to enable ssh https://github.com/nfarina/homebridge/wiki/FreeNAS-9.10-BSD-Jail \ No newline at end of file diff --git a/robots/auto_joe.json b/robots/auto_joe.json new file mode 100644 index 0000000..70ae615 --- /dev/null +++ b/robots/auto_joe.json @@ -0,0 +1,3 @@ +{ + "token":"" +} \ No newline at end of file diff --git a/robots/auto_joe.py b/robots/auto_joe.py new file mode 100644 index 0000000..d6dc604 --- /dev/null +++ b/robots/auto_joe.py @@ -0,0 +1,41 @@ +import discord +import sys +import os +import asyncio +import git +import time +import json + +g = git.cmd.Git('~/discord') + + +def restart_program(): # def defines a function, this one in particular restarts the program + #g.pull() # Would pull a new version from github if in a git repo + python = sys.executable # use executable in following line + os.execl(python, python, * sys.argv) # restart + + +client = discord.Client() +@client.event # On any event from the discord connection (client) +async def on_message(message): #When a message comes in + content=message.content # Get the content of the message + user=message.author # Get the author of the message + channel=message.channel # the the channel the message was sent in + + if user == client.user: # If the user is the robot itself + return # dont say anything in response to something the robot says + + if "cool beans" in content.strip(): # if in the string content, exists "cool beans" + time.sleep(2) # Wait a minute + await channel.send("Cool Beans") # using await so we sync with discord API, send cool beans ASAP + + if "define the word is" in content.strip(): + print("doot") + await channel.send("Rebooted") + restart_program() # call function + +with open("auto_joe.json", "r") as f: + robot_data = json.load(f) + +print("Starting robot with id: " + (robot_data["token"])) +client.run(robot_data["token"]) From d1c381ae17bfb434c6f1a1ff99deb68d134fe4cd Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Tue, 19 Nov 2019 17:19:51 -0500 Subject: [PATCH 2/9] Ignore changes to *.json files --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7043ff1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ + +*.json From 3ec619f19d4007503bc81306a9fe59ba009e5e72 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Tue, 19 Nov 2019 17:47:08 -0500 Subject: [PATCH 3/9] Updat the softwr --- robots/auto_joe.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/robots/auto_joe.py b/robots/auto_joe.py index d6dc604..e61c9d1 100644 --- a/robots/auto_joe.py +++ b/robots/auto_joe.py @@ -27,12 +27,17 @@ async def on_message(message): #When a message comes in if "cool beans" in content.strip(): # if in the string content, exists "cool beans" time.sleep(2) # Wait a minute + print("Yeah that was pretty cool beans") await channel.send("Cool Beans") # using await so we sync with discord API, send cool beans ASAP if "define the word is" in content.strip(): - print("doot") + print("Reboot called by " + str(user)) await channel.send("Rebooted") restart_program() # call function + + if ":0" in content.strip(): + print(":0") + await channel.send(":0") with open("auto_joe.json", "r") as f: robot_data = json.load(f) From 5dd81c09428a4229308a420512f2deee41aa9a0a Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Wed, 20 Nov 2019 08:03:01 -0500 Subject: [PATCH 4/9] Update git ignore to ignore the file containing the key for auto_joe --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 7043ff1..dcf65eb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -*.json +auto_joe.json From 1f4c7fab5bc34ebb8325477c11873bde16c83bc4 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Wed, 20 Nov 2019 08:13:14 -0500 Subject: [PATCH 5/9] Robot now reads off a pre-programed list of responses --- robots/auto_joe.py | 14 ++++++-------- robots/auto_joe_responses.json | 5 +++++ 2 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 robots/auto_joe_responses.json diff --git a/robots/auto_joe.py b/robots/auto_joe.py index e61c9d1..2af817a 100644 --- a/robots/auto_joe.py +++ b/robots/auto_joe.py @@ -8,6 +8,8 @@ g = git.cmd.Git('~/discord') +with open("auto_joe_responses.json", "r") as f: # Load all the responses + responses = json.load(f) def restart_program(): # def defines a function, this one in particular restarts the program #g.pull() # Would pull a new version from github if in a git repo @@ -25,19 +27,15 @@ async def on_message(message): #When a message comes in if user == client.user: # If the user is the robot itself return # dont say anything in response to something the robot says - if "cool beans" in content.strip(): # if in the string content, exists "cool beans" - time.sleep(2) # Wait a minute - print("Yeah that was pretty cool beans") - await channel.send("Cool Beans") # using await so we sync with discord API, send cool beans ASAP + for key in responses: + if key.upper() in (content.strip()).upper(): # if in the string content, exists "cool beans" + print(responses[key]) + await channel.send(responses[key]) # using await so we sync with discord API, send cool beans ASAP if "define the word is" in content.strip(): print("Reboot called by " + str(user)) await channel.send("Rebooted") restart_program() # call function - - if ":0" in content.strip(): - print(":0") - await channel.send(":0") with open("auto_joe.json", "r") as f: robot_data = json.load(f) diff --git a/robots/auto_joe_responses.json b/robots/auto_joe_responses.json new file mode 100644 index 0000000..f3454c9 --- /dev/null +++ b/robots/auto_joe_responses.json @@ -0,0 +1,5 @@ +{ + ":0":":0", + "What is the meaning of life":"42.", + "When is vive fest":"The 30th! WOO LETS GO!" +} \ No newline at end of file From 55b7e2f7208788d7efabf05adebd4fc42b63132c Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Wed, 20 Nov 2019 09:02:46 -0500 Subject: [PATCH 6/9] Add comments --- robots/auto_joe.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/robots/auto_joe.py b/robots/auto_joe.py index 2af817a..dc188fe 100644 --- a/robots/auto_joe.py +++ b/robots/auto_joe.py @@ -27,10 +27,10 @@ async def on_message(message): #When a message comes in if user == client.user: # If the user is the robot itself return # dont say anything in response to something the robot says - for key in responses: - if key.upper() in (content.strip()).upper(): # if in the string content, exists "cool beans" - print(responses[key]) - await channel.send(responses[key]) # using await so we sync with discord API, send cool beans ASAP + for key in responses: # For all the keys in the loaded dict + if key.upper() in (content.strip()).upper(): # if in the string content, exists the content of the key (ignoring uppercase) + print(responses[key]) # Log the update + await channel.send(responses[key]) # using await so we sync with discord API, send the message ASAP if "define the word is" in content.strip(): print("Reboot called by " + str(user)) From 37fe272c301108558b758a8a5900a5fb4dded0d6 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Fri, 22 Nov 2019 18:32:03 -0500 Subject: [PATCH 7/9] Update auto_joe_responses.json --- robots/auto_joe_responses.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/robots/auto_joe_responses.json b/robots/auto_joe_responses.json index f3454c9..9b50947 100644 --- a/robots/auto_joe_responses.json +++ b/robots/auto_joe_responses.json @@ -1,5 +1,8 @@ { ":0":":0", "What is the meaning of life":"42.", - "When is vive fest":"The 30th! WOO LETS GO!" + "When is vive fest":"The 30th! WOO LETS GO!", + "How do i download more ram":"Its easy, simply go here: https://downloadmoreram.com/", + "AutoJoe can i see an example of":"Nope, that feature is not available yet.", + "can you do my homework":"If i could do your homework do you think i would be here?" } \ No newline at end of file From dcfd804b6e2c3d7cf37c79c5465db9c719e1966d Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Mon, 25 Nov 2019 08:42:11 -0500 Subject: [PATCH 8/9] Create requirements.txt --- robots/requirements.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 robots/requirements.txt diff --git a/robots/requirements.txt b/robots/requirements.txt new file mode 100644 index 0000000..5afbb65 --- /dev/null +++ b/robots/requirements.txt @@ -0,0 +1,3 @@ +async-timeout==3.0.1 +discord.py==1.2.3 +GitPython==3.0.3 \ No newline at end of file From eabbfe8f0c02525acfbc4e3fda0e3d77ccb371b4 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Mon, 25 Nov 2019 09:28:11 -0500 Subject: [PATCH 9/9] Updated the responses --- robots/auto_joe_responses.json | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/robots/auto_joe_responses.json b/robots/auto_joe_responses.json index 9b50947..6e77846 100644 --- a/robots/auto_joe_responses.json +++ b/robots/auto_joe_responses.json @@ -4,5 +4,9 @@ "When is vive fest":"The 30th! WOO LETS GO!", "How do i download more ram":"Its easy, simply go here: https://downloadmoreram.com/", "AutoJoe can i see an example of":"Nope, that feature is not available yet.", - "can you do my homework":"If i could do your homework do you think i would be here?" -} \ No newline at end of file + "can you do my homework":"If i could do your homework do you think i would be here?", + "classroom code":"I dont actually know what it is lol for B or C block", + "who is joe":"Joe mamma", + "beep beep boop":"What?! My mother was a saint!", + "Where is my dinner":"Honey im home" +}