From 27e3ea9a90552a2c4be3680da7141ada57e128d2 Mon Sep 17 00:00:00 2001 From: abluey Date: Mon, 19 Jul 2021 20:07:09 +0800 Subject: [PATCH 01/30] added requirements.txt --- Zoe/requirements.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 Zoe/requirements.txt diff --git a/Zoe/requirements.txt b/Zoe/requirements.txt new file mode 100644 index 0000000..7750a0e --- /dev/null +++ b/Zoe/requirements.txt @@ -0,0 +1 @@ +discord.py==1.7.3 \ No newline at end of file From 34edeeef99efc2dc6d3baf60777d6d11ff014df6 Mon Sep 17 00:00:00 2001 From: abluey Date: Mon, 19 Jul 2021 20:21:59 +0800 Subject: [PATCH 02/30] Updated requirements; added pong for bot --- Zoe/main.py | 15 +++++++++++++++ Zoe/requirements.txt | 3 ++- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 Zoe/main.py diff --git a/Zoe/main.py b/Zoe/main.py new file mode 100644 index 0000000..87406d0 --- /dev/null +++ b/Zoe/main.py @@ -0,0 +1,15 @@ +import discord +client = discord.Client() + +@client.event +async def on_ready(): + print(f"Bot user {client.user} is ready.") + +@client.event +async def on_message(msg): + if msg.author == client.user: + return # Don’t respond to itself + if msg.content == "Ping": # Check that the message content matches + await msg.channel.send("Pong!") # If it does, reply + +bot.run() \ No newline at end of file diff --git a/Zoe/requirements.txt b/Zoe/requirements.txt index 7750a0e..4325d90 100644 --- a/Zoe/requirements.txt +++ b/Zoe/requirements.txt @@ -1 +1,2 @@ -discord.py==1.7.3 \ No newline at end of file +discord.py==1.7.3 +python==3.9.6 \ No newline at end of file From 285b870933894a96b63f9f21b6239142277d979b Mon Sep 17 00:00:00 2001 From: abluey Date: Mon, 19 Jul 2021 20:34:35 +0800 Subject: [PATCH 03/30] updated requirements; added discord token --- Zoe/main.py | 7 ++++++- Zoe/requirements.txt | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Zoe/main.py b/Zoe/main.py index 87406d0..3e2aa51 100644 --- a/Zoe/main.py +++ b/Zoe/main.py @@ -1,4 +1,8 @@ +import os import discord + +from dotenv import load_dotenv + client = discord.Client() @client.event @@ -12,4 +16,5 @@ async def on_message(msg): if msg.content == "Ping": # Check that the message content matches await msg.channel.send("Pong!") # If it does, reply -bot.run() \ No newline at end of file +load_dotenv() +client.run(os.environ['TOKEN']) \ No newline at end of file diff --git a/Zoe/requirements.txt b/Zoe/requirements.txt index 4325d90..059f36f 100644 --- a/Zoe/requirements.txt +++ b/Zoe/requirements.txt @@ -1,2 +1,3 @@ discord.py==1.7.3 -python==3.9.6 \ No newline at end of file +python==3.9.6 +python-dotenv==0.18.0 \ No newline at end of file From 6ad5cb8c306b085bf59f6eabe10c1b3b77a9a8c1 Mon Sep 17 00:00:00 2001 From: abluey Date: Mon, 19 Jul 2021 20:37:55 +0800 Subject: [PATCH 04/30] updated token calls --- Zoe/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Zoe/main.py b/Zoe/main.py index 3e2aa51..5e67587 100644 --- a/Zoe/main.py +++ b/Zoe/main.py @@ -17,4 +17,5 @@ async def on_message(msg): await msg.channel.send("Pong!") # If it does, reply load_dotenv() -client.run(os.environ['TOKEN']) \ No newline at end of file +BOT_TOKEN=os.environ['TOKEN'] +client.run(BOT_TOKEN) \ No newline at end of file From a30ad40b0a5ca77fea40b4325c1ef72dafc122ce Mon Sep 17 00:00:00 2001 From: abluey Date: Mon, 19 Jul 2021 20:52:39 +0800 Subject: [PATCH 05/30] added greeting command --- Zoe/main.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Zoe/main.py b/Zoe/main.py index 5e67587..e94b330 100644 --- a/Zoe/main.py +++ b/Zoe/main.py @@ -1,9 +1,11 @@ import os import discord +from discord.ext import commands from dotenv import load_dotenv client = discord.Client() +bot = commands.Bot(command_prefix='!') @client.event async def on_ready(): @@ -16,6 +18,14 @@ async def on_message(msg): if msg.content == "Ping": # Check that the message content matches await msg.channel.send("Pong!") # If it does, reply +@bot.command(name="hey") +async def hey(ctx, *, args): + if args: + await ctx.send("Hey " + args) + else: + await ctx.send("Hey " + ctx.message.author.name) + + load_dotenv() BOT_TOKEN=os.environ['TOKEN'] client.run(BOT_TOKEN) \ No newline at end of file From 625a932c8fd738e778a4dbf0779727911d4e41f5 Mon Sep 17 00:00:00 2001 From: abluey Date: Mon, 19 Jul 2021 20:54:51 +0800 Subject: [PATCH 06/30] bot now processes commands --- Zoe/main.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Zoe/main.py b/Zoe/main.py index e94b330..ba2229e 100644 --- a/Zoe/main.py +++ b/Zoe/main.py @@ -14,9 +14,12 @@ async def on_ready(): @client.event async def on_message(msg): if msg.author == client.user: - return # Don’t respond to itself - if msg.content == "Ping": # Check that the message content matches - await msg.channel.send("Pong!") # If it does, reply + return + + await bot.process_commands(msg) + + if msg.content == "Ping": + await msg.channel.send("Pong!") @bot.command(name="hey") async def hey(ctx, *, args): From 72bcd14706bede7862b555e2b1a1ceca1187b258 Mon Sep 17 00:00:00 2001 From: abluey Date: Mon, 19 Jul 2021 20:56:48 +0800 Subject: [PATCH 07/30] Modified bot processing commands --- Zoe/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Zoe/main.py b/Zoe/main.py index ba2229e..5436610 100644 --- a/Zoe/main.py +++ b/Zoe/main.py @@ -16,10 +16,10 @@ async def on_message(msg): if msg.author == client.user: return - await bot.process_commands(msg) - if msg.content == "Ping": await msg.channel.send("Pong!") + else: + await bot.process_commands(msg) @bot.command(name="hey") async def hey(ctx, *, args): From cf2dcfbfea7c22144163cb690ec641b7b3ef4e6b Mon Sep 17 00:00:00 2001 From: abluey Date: Mon, 19 Jul 2021 21:02:16 +0800 Subject: [PATCH 08/30] Modified greeting command again --- Zoe/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Zoe/main.py b/Zoe/main.py index 5436610..2982f24 100644 --- a/Zoe/main.py +++ b/Zoe/main.py @@ -15,11 +15,11 @@ async def on_ready(): async def on_message(msg): if msg.author == client.user: return + + await bot.process_commands(msg) if msg.content == "Ping": await msg.channel.send("Pong!") - else: - await bot.process_commands(msg) @bot.command(name="hey") async def hey(ctx, *, args): From 74872ebef329523bd243333442649e4fe950dd9a Mon Sep 17 00:00:00 2001 From: abluey Date: Mon, 19 Jul 2021 21:03:08 +0800 Subject: [PATCH 09/30] Modified bot command again --- Zoe/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Zoe/main.py b/Zoe/main.py index 2982f24..9d580b7 100644 --- a/Zoe/main.py +++ b/Zoe/main.py @@ -15,12 +15,12 @@ async def on_ready(): async def on_message(msg): if msg.author == client.user: return - - await bot.process_commands(msg) if msg.content == "Ping": await msg.channel.send("Pong!") + await bot.process_commands(msg) + @bot.command(name="hey") async def hey(ctx, *, args): if args: From f3d8745a873097d3a27e44cd746b695f81244214 Mon Sep 17 00:00:00 2001 From: abluey Date: Mon, 19 Jul 2021 21:04:58 +0800 Subject: [PATCH 10/30] deleted client and changed everything to bot --- Zoe/main.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Zoe/main.py b/Zoe/main.py index 9d580b7..4815e4f 100644 --- a/Zoe/main.py +++ b/Zoe/main.py @@ -4,16 +4,15 @@ from dotenv import load_dotenv -client = discord.Client() bot = commands.Bot(command_prefix='!') -@client.event +@bot.event async def on_ready(): - print(f"Bot user {client.user} is ready.") + print(f"Bot user {bot.user} is ready.") -@client.event +@bot.event async def on_message(msg): - if msg.author == client.user: + if msg.author == bot.user: return if msg.content == "Ping": @@ -31,4 +30,4 @@ async def hey(ctx, *, args): load_dotenv() BOT_TOKEN=os.environ['TOKEN'] -client.run(BOT_TOKEN) \ No newline at end of file +bot.run(BOT_TOKEN) \ No newline at end of file From 44c1332eac87807f77f0916309144bbe2fcf25ec Mon Sep 17 00:00:00 2001 From: abluey Date: Mon, 19 Jul 2021 21:12:30 +0800 Subject: [PATCH 11/30] Changed the hey command --- Zoe/main.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Zoe/main.py b/Zoe/main.py index 4815e4f..a7c10c8 100644 --- a/Zoe/main.py +++ b/Zoe/main.py @@ -21,11 +21,11 @@ async def on_message(msg): await bot.process_commands(msg) @bot.command(name="hey") -async def hey(ctx, *, args): - if args: - await ctx.send("Hey " + args) +async def hey(ctx, name = None): + if name: + await ctx.send("Hey " + name + " :)") else: - await ctx.send("Hey " + ctx.message.author.name) + await ctx.send("Hey " + ctx.message.author.name + " :)") load_dotenv() From 75c63c215ff6074bf35bd37a40d52f666422900f Mon Sep 17 00:00:00 2001 From: abluey Date: Mon, 19 Jul 2021 21:18:09 +0800 Subject: [PATCH 12/30] added thief easter egg --- Zoe/main.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Zoe/main.py b/Zoe/main.py index a7c10c8..2442307 100644 --- a/Zoe/main.py +++ b/Zoe/main.py @@ -18,12 +18,18 @@ async def on_message(msg): if msg.content == "Ping": await msg.channel.send("Pong!") + if msg.content.lower == "no one calls esteban julio ricardo montoya de la rosa ramírez a thief!": + await msg.channel.send("NO ONE'S GOT THE TIME") + await bot.process_commands(msg) @bot.command(name="hey") async def hey(ctx, name = None): if name: - await ctx.send("Hey " + name + " :)") + if name.lower() == "esteban julio ricardo montoya de la rosa ramírez": + await ctx.send("Hey theif") + else: + await ctx.send("Hey " + name + " :)") else: await ctx.send("Hey " + ctx.message.author.name + " :)") From 322094a7b75949d5433510e1af772f567bc295e5 Mon Sep 17 00:00:00 2001 From: abluey Date: Mon, 19 Jul 2021 21:19:03 +0800 Subject: [PATCH 13/30] updated hey command --- Zoe/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Zoe/main.py b/Zoe/main.py index 2442307..fead364 100644 --- a/Zoe/main.py +++ b/Zoe/main.py @@ -20,11 +20,11 @@ async def on_message(msg): if msg.content.lower == "no one calls esteban julio ricardo montoya de la rosa ramírez a thief!": await msg.channel.send("NO ONE'S GOT THE TIME") - + await bot.process_commands(msg) @bot.command(name="hey") -async def hey(ctx, name = None): +async def hey(ctx, *, name = None): if name: if name.lower() == "esteban julio ricardo montoya de la rosa ramírez": await ctx.send("Hey theif") From 341205e81ea1076638d6b6dc2257f44a30b3472b Mon Sep 17 00:00:00 2001 From: abluey Date: Mon, 19 Jul 2021 21:26:19 +0800 Subject: [PATCH 14/30] added sort command; fixed hey easter egg --- Zoe/main.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Zoe/main.py b/Zoe/main.py index fead364..026fc77 100644 --- a/Zoe/main.py +++ b/Zoe/main.py @@ -18,21 +18,26 @@ async def on_message(msg): if msg.content == "Ping": await msg.channel.send("Pong!") - if msg.content.lower == "no one calls esteban julio ricardo montoya de la rosa ramírez a thief!": + if msg.content.lower() == "no one calls esteban julio ricardo montoya de la rosa ramírez a thief!": await msg.channel.send("NO ONE'S GOT THE TIME") await bot.process_commands(msg) @bot.command(name="hey") -async def hey(ctx, *, name = None): +async def hey(ctx, *, name=None): if name: if name.lower() == "esteban julio ricardo montoya de la rosa ramírez": - await ctx.send("Hey theif") + await ctx.send("Hey thief") else: await ctx.send("Hey " + name + " :)") else: await ctx.send("Hey " + ctx.message.author.name + " :)") +@bot.command() +async def sort(ctx, *args): + newArgs = args.sort() + await ctx.send('{} arguments: {}'.format(len(args), ', '.join(newArgs))) + load_dotenv() BOT_TOKEN=os.environ['TOKEN'] From 5dfaab77ff395e066909cbf431b186ed01e894d8 Mon Sep 17 00:00:00 2001 From: abluey Date: Mon, 19 Jul 2021 21:28:41 +0800 Subject: [PATCH 15/30] fixed sort command --- Zoe/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zoe/main.py b/Zoe/main.py index 026fc77..f1fc2eb 100644 --- a/Zoe/main.py +++ b/Zoe/main.py @@ -35,7 +35,7 @@ async def hey(ctx, *, name=None): @bot.command() async def sort(ctx, *args): - newArgs = args.sort() + newArgs = list(args).sort() await ctx.send('{} arguments: {}'.format(len(args), ', '.join(newArgs))) From 5e95edfde46c38b778d705c1e6fe287d41260e24 Mon Sep 17 00:00:00 2001 From: abluey Date: Mon, 19 Jul 2021 21:39:46 +0800 Subject: [PATCH 16/30] fixed sort command! --- Zoe/main.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Zoe/main.py b/Zoe/main.py index f1fc2eb..2803c73 100644 --- a/Zoe/main.py +++ b/Zoe/main.py @@ -35,8 +35,16 @@ async def hey(ctx, *, name=None): @bot.command() async def sort(ctx, *args): - newArgs = list(args).sort() - await ctx.send('{} arguments: {}'.format(len(args), ', '.join(newArgs))) + argsList = [] + for item in args: + argsList.append(item) + argsList.sort() + + output = "{} arguments: ".format(len(args)) + for item in argsList: + output += item + " " + + await ctx.send(output) load_dotenv() From e3cb1faedf7205be9f7817a9f75421ecea52b5b9 Mon Sep 17 00:00:00 2001 From: abluey Date: Mon, 19 Jul 2021 21:56:06 +0800 Subject: [PATCH 17/30] Put commands into cogs --- Zoe/cogs/greetings.py | 18 ++++++++++++++++++ Zoe/cogs/sort.py | 18 ++++++++++++++++++ Zoe/main.py | 28 +++------------------------- 3 files changed, 39 insertions(+), 25 deletions(-) create mode 100644 Zoe/cogs/greetings.py create mode 100644 Zoe/cogs/sort.py diff --git a/Zoe/cogs/greetings.py b/Zoe/cogs/greetings.py new file mode 100644 index 0000000..6def4f4 --- /dev/null +++ b/Zoe/cogs/greetings.py @@ -0,0 +1,18 @@ +import discord +from discord.ext import commands + +class Greetings(commands.Cog): + def __init__(self, bot): + self.bot = bot + + async def hey(ctx, *, name=None): + if name: + if name.lower() == "esteban julio ricardo montoya de la rosa ramírez": + await ctx.send("Hey thief") + else: + await ctx.send("Hey " + name + " :)") + else: + await ctx.send("Hey " + ctx.message.author.name + " :)") + +def setup(bot): + bot.add_cog(Greetings(bot)) \ No newline at end of file diff --git a/Zoe/cogs/sort.py b/Zoe/cogs/sort.py new file mode 100644 index 0000000..2e40371 --- /dev/null +++ b/Zoe/cogs/sort.py @@ -0,0 +1,18 @@ +import discord +from discord.ext import commands + +class Sort(commands.Cog): + async def sort(ctx, *args): + argsList = [] + for item in args: + argsList.append(item) + argsList.sort() + + output = "{} arguments: ".format(len(args)) + for item in argsList: + output += item + " " + + await ctx.send(output) + +def setup(bot): + bot.add_cog(Sort(bot)) \ No newline at end of file diff --git a/Zoe/main.py b/Zoe/main.py index 2803c73..1698d5e 100644 --- a/Zoe/main.py +++ b/Zoe/main.py @@ -9,6 +9,9 @@ @bot.event async def on_ready(): print(f"Bot user {bot.user} is ready.") + bot.load_extension("cogs.greetings") + bot.load_extension("cogs.sort") + @bot.event async def on_message(msg): @@ -21,31 +24,6 @@ async def on_message(msg): if msg.content.lower() == "no one calls esteban julio ricardo montoya de la rosa ramírez a thief!": await msg.channel.send("NO ONE'S GOT THE TIME") - await bot.process_commands(msg) - -@bot.command(name="hey") -async def hey(ctx, *, name=None): - if name: - if name.lower() == "esteban julio ricardo montoya de la rosa ramírez": - await ctx.send("Hey thief") - else: - await ctx.send("Hey " + name + " :)") - else: - await ctx.send("Hey " + ctx.message.author.name + " :)") - -@bot.command() -async def sort(ctx, *args): - argsList = [] - for item in args: - argsList.append(item) - argsList.sort() - - output = "{} arguments: ".format(len(args)) - for item in argsList: - output += item + " " - - await ctx.send(output) - load_dotenv() BOT_TOKEN=os.environ['TOKEN'] From 5fa6bc8007d89a5770d2d71e8cc9dd8bbccd05cc Mon Sep 17 00:00:00 2001 From: abluey Date: Mon, 19 Jul 2021 22:02:26 +0800 Subject: [PATCH 18/30] added "Easter egg" for testing purposes --- Zoe/main.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Zoe/main.py b/Zoe/main.py index 1698d5e..25a1d48 100644 --- a/Zoe/main.py +++ b/Zoe/main.py @@ -21,6 +21,9 @@ async def on_message(msg): if msg.content == "Ping": await msg.channel.send("Pong!") + if msg.content == "easter": + await msg.channel.send("egg") + if msg.content.lower() == "no one calls esteban julio ricardo montoya de la rosa ramírez a thief!": await msg.channel.send("NO ONE'S GOT THE TIME") From 8ef60276b3d72ca6d1a077e26d919dcf6784041c Mon Sep 17 00:00:00 2001 From: abluey Date: Mon, 19 Jul 2021 22:07:31 +0800 Subject: [PATCH 19/30] commented out ping pong --- Zoe/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Zoe/main.py b/Zoe/main.py index 25a1d48..8a88c85 100644 --- a/Zoe/main.py +++ b/Zoe/main.py @@ -18,8 +18,8 @@ async def on_message(msg): if msg.author == bot.user: return - if msg.content == "Ping": - await msg.channel.send("Pong!") + # if msg.content == "Ping": + # await msg.channel.send("Pong!") if msg.content == "easter": await msg.channel.send("egg") From 5120d2b3ce778fa5143cf1f76bb7f9c1303df92d Mon Sep 17 00:00:00 2001 From: abluey Date: Mon, 19 Jul 2021 22:11:15 +0800 Subject: [PATCH 20/30] uncommented ping pong --- Zoe/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Zoe/main.py b/Zoe/main.py index 8a88c85..25a1d48 100644 --- a/Zoe/main.py +++ b/Zoe/main.py @@ -18,8 +18,8 @@ async def on_message(msg): if msg.author == bot.user: return - # if msg.content == "Ping": - # await msg.channel.send("Pong!") + if msg.content == "Ping": + await msg.channel.send("Pong!") if msg.content == "easter": await msg.channel.send("egg") From 5bc7a7af58b7278e2c9f44e4c6ba384ed56d1d07 Mon Sep 17 00:00:00 2001 From: abluey Date: Mon, 19 Jul 2021 22:18:07 +0800 Subject: [PATCH 21/30] updated cogs --- Zoe/cogs/greetings.py | 3 ++- Zoe/cogs/sort.py | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Zoe/cogs/greetings.py b/Zoe/cogs/greetings.py index 6def4f4..fda6829 100644 --- a/Zoe/cogs/greetings.py +++ b/Zoe/cogs/greetings.py @@ -5,7 +5,8 @@ class Greetings(commands.Cog): def __init__(self, bot): self.bot = bot - async def hey(ctx, *, name=None): + @commands.command() + async def hey(self, ctx, *, name=None): if name: if name.lower() == "esteban julio ricardo montoya de la rosa ramírez": await ctx.send("Hey thief") diff --git a/Zoe/cogs/sort.py b/Zoe/cogs/sort.py index 2e40371..469f5e8 100644 --- a/Zoe/cogs/sort.py +++ b/Zoe/cogs/sort.py @@ -2,7 +2,11 @@ from discord.ext import commands class Sort(commands.Cog): - async def sort(ctx, *args): + def __init__(self, bot): + self.bot = bot + + @commands.command() + async def sort(self, ctx, *args): argsList = [] for item in args: argsList.append(item) From 8525b5512e504f3fcb48c08934bb9471e3eef55d Mon Sep 17 00:00:00 2001 From: abluey Date: Mon, 19 Jul 2021 22:27:11 +0800 Subject: [PATCH 22/30] cogs now work properly --- Zoe/cogs/greetings.py | 7 +++++-- Zoe/cogs/sort.py | 4 +++- Zoe/main.py | 2 ++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Zoe/cogs/greetings.py b/Zoe/cogs/greetings.py index fda6829..737300c 100644 --- a/Zoe/cogs/greetings.py +++ b/Zoe/cogs/greetings.py @@ -2,11 +2,13 @@ from discord.ext import commands class Greetings(commands.Cog): - def __init__(self, bot): + + def __init__(self, bot: commands.Bot): self.bot = bot @commands.command() async def hey(self, ctx, *, name=None): + print("hey command called") if name: if name.lower() == "esteban julio ricardo montoya de la rosa ramírez": await ctx.send("Hey thief") @@ -16,4 +18,5 @@ async def hey(self, ctx, *, name=None): await ctx.send("Hey " + ctx.message.author.name + " :)") def setup(bot): - bot.add_cog(Greetings(bot)) \ No newline at end of file + bot.add_cog(Greetings(bot)) + print("cog loaded") \ No newline at end of file diff --git a/Zoe/cogs/sort.py b/Zoe/cogs/sort.py index 469f5e8..b345de0 100644 --- a/Zoe/cogs/sort.py +++ b/Zoe/cogs/sort.py @@ -2,6 +2,7 @@ from discord.ext import commands class Sort(commands.Cog): + def __init__(self, bot): self.bot = bot @@ -19,4 +20,5 @@ async def sort(self, ctx, *args): await ctx.send(output) def setup(bot): - bot.add_cog(Sort(bot)) \ No newline at end of file + bot.add_cog(Sort(bot)) + print("cog loaded") \ No newline at end of file diff --git a/Zoe/main.py b/Zoe/main.py index 25a1d48..f1e6d71 100644 --- a/Zoe/main.py +++ b/Zoe/main.py @@ -27,6 +27,8 @@ async def on_message(msg): if msg.content.lower() == "no one calls esteban julio ricardo montoya de la rosa ramírez a thief!": await msg.channel.send("NO ONE'S GOT THE TIME") + await bot.process_commands(msg) + load_dotenv() BOT_TOKEN=os.environ['TOKEN'] From ac7156598b4b9a4acdf92d5bfe65505809da39c2 Mon Sep 17 00:00:00 2001 From: abluey Date: Mon, 19 Jul 2021 22:27:22 +0800 Subject: [PATCH 23/30] cogs now work properly part 2 --- Zoe/cogs/greetings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zoe/cogs/greetings.py b/Zoe/cogs/greetings.py index 737300c..c01524b 100644 --- a/Zoe/cogs/greetings.py +++ b/Zoe/cogs/greetings.py @@ -3,7 +3,7 @@ class Greetings(commands.Cog): - def __init__(self, bot: commands.Bot): + def __init__(self, bot): self.bot = bot @commands.command() From e2a69c864d99d6328a67bba31063d9e1d2ee20de Mon Sep 17 00:00:00 2001 From: abluey Date: Mon, 19 Jul 2021 22:28:39 +0800 Subject: [PATCH 24/30] removed print statements --- Zoe/cogs/greetings.py | 4 +--- Zoe/cogs/sort.py | 3 +-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Zoe/cogs/greetings.py b/Zoe/cogs/greetings.py index c01524b..a1e4c98 100644 --- a/Zoe/cogs/greetings.py +++ b/Zoe/cogs/greetings.py @@ -8,7 +8,6 @@ def __init__(self, bot): @commands.command() async def hey(self, ctx, *, name=None): - print("hey command called") if name: if name.lower() == "esteban julio ricardo montoya de la rosa ramírez": await ctx.send("Hey thief") @@ -18,5 +17,4 @@ async def hey(self, ctx, *, name=None): await ctx.send("Hey " + ctx.message.author.name + " :)") def setup(bot): - bot.add_cog(Greetings(bot)) - print("cog loaded") \ No newline at end of file + bot.add_cog(Greetings(bot)) \ No newline at end of file diff --git a/Zoe/cogs/sort.py b/Zoe/cogs/sort.py index b345de0..52a44bb 100644 --- a/Zoe/cogs/sort.py +++ b/Zoe/cogs/sort.py @@ -20,5 +20,4 @@ async def sort(self, ctx, *args): await ctx.send(output) def setup(bot): - bot.add_cog(Sort(bot)) - print("cog loaded") \ No newline at end of file + bot.add_cog(Sort(bot)) \ No newline at end of file From a590d87adab40d0069dd3b38fd0898391dabe754 Mon Sep 17 00:00:00 2001 From: abluey Date: Tue, 20 Jul 2021 20:38:00 +0800 Subject: [PATCH 25/30] added greetings test --- .vscode/settings.json | 8 ++++++++ Zoe/cogs/random.py | 19 +++++++++++++++++++ Zoe/main.py | 1 + Zoe/requirements.txt | 2 ++ Zoe/tests/test_greetings.py | 24 ++++++++++++++++++++++++ 5 files changed, 54 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 Zoe/cogs/random.py create mode 100644 Zoe/tests/test_greetings.py diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..0ad1db6 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,8 @@ +{ + "python.testing.pytestArgs": [ + "Zoe" + ], + "python.testing.unittestEnabled": false, + "python.testing.nosetestsEnabled": false, + "python.testing.pytestEnabled": true +} \ No newline at end of file diff --git a/Zoe/cogs/random.py b/Zoe/cogs/random.py new file mode 100644 index 0000000..3b714eb --- /dev/null +++ b/Zoe/cogs/random.py @@ -0,0 +1,19 @@ +import discord +from discord.ext import commands + +import random + +class Random(commands.Cog): + + def __init__(self, bot): + self.bot = bot + + @commands.command() + async def random(self, ctx, number=None): + if number: + await ctx.send(random.randint(0, number)) + else: + await ctx.send(random.randint(0, 100)) + +def setup(bot): + bot.add_cog(Random(bot)) \ No newline at end of file diff --git a/Zoe/main.py b/Zoe/main.py index f1e6d71..881b156 100644 --- a/Zoe/main.py +++ b/Zoe/main.py @@ -11,6 +11,7 @@ async def on_ready(): print(f"Bot user {bot.user} is ready.") bot.load_extension("cogs.greetings") bot.load_extension("cogs.sort") + bot.load_extension("cogs.random") @bot.event diff --git a/Zoe/requirements.txt b/Zoe/requirements.txt index 059f36f..f32a730 100644 --- a/Zoe/requirements.txt +++ b/Zoe/requirements.txt @@ -1,3 +1,5 @@ discord.py==1.7.3 +dpytest==0.5.3 +pytest==6.2.4 python==3.9.6 python-dotenv==0.18.0 \ No newline at end of file diff --git a/Zoe/tests/test_greetings.py b/Zoe/tests/test_greetings.py new file mode 100644 index 0000000..3c04132 --- /dev/null +++ b/Zoe/tests/test_greetings.py @@ -0,0 +1,24 @@ +import asyncio +import pytest +import discord.ext.test as dpytest +import discord.ext.commands as commands + +from cogs import greetings + +@pytest.fixture +async def bot(event_loop): + b = commands.Bot("!", loop=event_loop) + dpytest.configure(b) + return b + +@pytest.fixture(autouse=True) +def greetings_cog(bot: commands.Bot): + greetings_cog = greetings.greetings(bot) + bot.add_cog(greetings_cog) + dpytest.configure(bot) + return greetings_cog + +@pytest.mark.asyncio +async def test_with_name(): + await dpytest.message("!hey abluey") + assert dpytest.verify().message().content("Hey abluey :)") \ No newline at end of file From a63a8a42aae921f233bdb90ae4cbc77f49eee376 Mon Sep 17 00:00:00 2001 From: abluey Date: Tue, 20 Jul 2021 22:14:05 +0800 Subject: [PATCH 26/30] added tests for random.py and greetings.py --- Zoe/cogs/random.py | 2 +- Zoe/requirements.txt | 1 - Zoe/tests/test_greetings.py | 20 +++++++++++++++----- Zoe/tests/test_random.py | 28 ++++++++++++++++++++++++++++ Zoe/tests/test_sort.py | 30 ++++++++++++++++++++++++++++++ 5 files changed, 74 insertions(+), 7 deletions(-) create mode 100644 Zoe/tests/test_random.py create mode 100644 Zoe/tests/test_sort.py diff --git a/Zoe/cogs/random.py b/Zoe/cogs/random.py index 3b714eb..f8bf186 100644 --- a/Zoe/cogs/random.py +++ b/Zoe/cogs/random.py @@ -11,7 +11,7 @@ def __init__(self, bot): @commands.command() async def random(self, ctx, number=None): if number: - await ctx.send(random.randint(0, number)) + await ctx.send(random.randint(0, int(number))) else: await ctx.send(random.randint(0, 100)) diff --git a/Zoe/requirements.txt b/Zoe/requirements.txt index f32a730..557f2eb 100644 --- a/Zoe/requirements.txt +++ b/Zoe/requirements.txt @@ -1,5 +1,4 @@ discord.py==1.7.3 dpytest==0.5.3 pytest==6.2.4 -python==3.9.6 python-dotenv==0.18.0 \ No newline at end of file diff --git a/Zoe/tests/test_greetings.py b/Zoe/tests/test_greetings.py index 3c04132..03f28f2 100644 --- a/Zoe/tests/test_greetings.py +++ b/Zoe/tests/test_greetings.py @@ -1,24 +1,34 @@ import asyncio import pytest +import discord import discord.ext.test as dpytest import discord.ext.commands as commands from cogs import greetings -@pytest.fixture +@pytest.fixture(autouse=True) async def bot(event_loop): - b = commands.Bot("!", loop=event_loop) + intents = discord.Intents.default() + intents.members = True + intents.messages = True + b = commands.Bot("!", loop=event_loop, intents=intents) dpytest.configure(b) return b @pytest.fixture(autouse=True) def greetings_cog(bot: commands.Bot): - greetings_cog = greetings.greetings(bot) + greetings_cog = greetings.Greetings(bot) bot.add_cog(greetings_cog) dpytest.configure(bot) return greetings_cog @pytest.mark.asyncio async def test_with_name(): - await dpytest.message("!hey abluey") - assert dpytest.verify().message().content("Hey abluey :)") \ No newline at end of file + await dpytest.message("!hey john") + assert dpytest.verify().message().content("Hey john :)") + +# :( +@pytest.mark.asyncio +async def test_without_name(): + await dpytest.message("!hey") + assert dpytest.verify().message().content("Hey TestUser0 :)") \ No newline at end of file diff --git a/Zoe/tests/test_random.py b/Zoe/tests/test_random.py new file mode 100644 index 0000000..1eb6ca2 --- /dev/null +++ b/Zoe/tests/test_random.py @@ -0,0 +1,28 @@ +import asyncio +import pytest +import discord +import discord.ext.test as dpytest +import discord.ext.commands as commands + +from cogs import random + +@pytest.fixture(autouse=True) +async def bot(event_loop): + intents = discord.Intents.default() + intents.members = True + intents.messages = True + b = commands.Bot("!", loop=event_loop, intents=intents) + dpytest.configure(b) + return b + +@pytest.fixture(autouse=True) +def random_cog(bot: commands.Bot): + random_cog = random.Random(bot) + bot.add_cog(random_cog) + dpytest.configure(bot) + return random_cog + +@pytest.mark.asyncio +async def test_with_param(): + await dpytest.message("!random 0") + assert dpytest.verify().message().content("0") \ No newline at end of file diff --git a/Zoe/tests/test_sort.py b/Zoe/tests/test_sort.py new file mode 100644 index 0000000..994ab1e --- /dev/null +++ b/Zoe/tests/test_sort.py @@ -0,0 +1,30 @@ +import asyncio +import pytest +import discord +import discord.ext.test as dpytest +import discord.ext.commands as commands + +from cogs import sort + +@pytest.fixture(autouse=True) +async def bot(event_loop): + intents = discord.Intents.default() + intents.members = True + intents.messages = True + b = commands.Bot("!", loop=event_loop, intents=intents) + dpytest.configure(b) + return b + +@pytest.fixture(autouse=True) +def sort_cog(bot: commands.Bot): + sort_cog = sort.Sort(bot) + bot.add_cog(sort_cog) + dpytest.configure(bot) + return sort_cog + +@pytest.mark.asyncio +async def test_sort(): + await dpytest.message("!sort house dog") + msg = dpytest.sent_queue.peek() + print(msg.content) + assert dpytest.verify().message().content("2 arguments: dog house"), msg.content \ No newline at end of file From aaacce4a8be25cef115eb62d52a301b08bcc1b3b Mon Sep 17 00:00:00 2001 From: abluey Date: Tue, 20 Jul 2021 22:28:40 +0800 Subject: [PATCH 27/30] fixed sort test --- Zoe/cogs/sort.py | 5 ++++- Zoe/tests/test_sort.py | 1 - 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Zoe/cogs/sort.py b/Zoe/cogs/sort.py index 52a44bb..228e516 100644 --- a/Zoe/cogs/sort.py +++ b/Zoe/cogs/sort.py @@ -15,7 +15,10 @@ async def sort(self, ctx, *args): output = "{} arguments: ".format(len(args)) for item in argsList: - output += item + " " + if item == argsList[0]: + output += item + else: + output += " " + item await ctx.send(output) diff --git a/Zoe/tests/test_sort.py b/Zoe/tests/test_sort.py index 994ab1e..0ec26db 100644 --- a/Zoe/tests/test_sort.py +++ b/Zoe/tests/test_sort.py @@ -26,5 +26,4 @@ def sort_cog(bot: commands.Bot): async def test_sort(): await dpytest.message("!sort house dog") msg = dpytest.sent_queue.peek() - print(msg.content) assert dpytest.verify().message().content("2 arguments: dog house"), msg.content \ No newline at end of file From d80831093b115195522b372d50ad72889ac381fa Mon Sep 17 00:00:00 2001 From: abluey Date: Tue, 20 Jul 2021 22:35:42 +0800 Subject: [PATCH 28/30] added random number test --- Zoe/tests/test_greetings.py | 1 - Zoe/tests/test_random.py | 8 +++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Zoe/tests/test_greetings.py b/Zoe/tests/test_greetings.py index 03f28f2..a7c7e38 100644 --- a/Zoe/tests/test_greetings.py +++ b/Zoe/tests/test_greetings.py @@ -27,7 +27,6 @@ async def test_with_name(): await dpytest.message("!hey john") assert dpytest.verify().message().content("Hey john :)") -# :( @pytest.mark.asyncio async def test_without_name(): await dpytest.message("!hey") diff --git a/Zoe/tests/test_random.py b/Zoe/tests/test_random.py index 1eb6ca2..1c8a1e8 100644 --- a/Zoe/tests/test_random.py +++ b/Zoe/tests/test_random.py @@ -25,4 +25,10 @@ def random_cog(bot: commands.Bot): @pytest.mark.asyncio async def test_with_param(): await dpytest.message("!random 0") - assert dpytest.verify().message().content("0") \ No newline at end of file + assert dpytest.verify().message().content("0") + +@pytest.mark.asyncio +async def test_without_param(): + await dpytest.message("!random") + msg = dpytest.sent_queue.peek() + assert int(msg.content) < 100 \ No newline at end of file From cdf476175241fd62d8cec1502b5e75e217ddc2fe Mon Sep 17 00:00:00 2001 From: abluey Date: Tue, 20 Jul 2021 22:50:43 +0800 Subject: [PATCH 29/30] fixed sort tests and added one more to it --- Zoe/cogs/sort.py | 15 +++++++++------ Zoe/tests/test_random.py | 3 ++- Zoe/tests/test_sort.py | 8 +++++++- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Zoe/cogs/sort.py b/Zoe/cogs/sort.py index 228e516..3a095a8 100644 --- a/Zoe/cogs/sort.py +++ b/Zoe/cogs/sort.py @@ -13,12 +13,15 @@ async def sort(self, ctx, *args): argsList.append(item) argsList.sort() - output = "{} arguments: ".format(len(args)) - for item in argsList: - if item == argsList[0]: - output += item - else: - output += " " + item + if argsList: + output = "{} arguments: ".format(len(args)) + for item in argsList: + if item == argsList[0]: + output += item + else: + output += " " + item + else: + output = "No arguments found." await ctx.send(output) diff --git a/Zoe/tests/test_random.py b/Zoe/tests/test_random.py index 1c8a1e8..9ca1d78 100644 --- a/Zoe/tests/test_random.py +++ b/Zoe/tests/test_random.py @@ -13,6 +13,7 @@ async def bot(event_loop): intents.messages = True b = commands.Bot("!", loop=event_loop, intents=intents) dpytest.configure(b) + await dpytest.empty_queue() return b @pytest.fixture(autouse=True) @@ -31,4 +32,4 @@ async def test_with_param(): async def test_without_param(): await dpytest.message("!random") msg = dpytest.sent_queue.peek() - assert int(msg.content) < 100 \ No newline at end of file + assert int(msg.content) <= 100 \ No newline at end of file diff --git a/Zoe/tests/test_sort.py b/Zoe/tests/test_sort.py index 0ec26db..8c72a72 100644 --- a/Zoe/tests/test_sort.py +++ b/Zoe/tests/test_sort.py @@ -13,6 +13,7 @@ async def bot(event_loop): intents.messages = True b = commands.Bot("!", loop=event_loop, intents=intents) dpytest.configure(b) + await dpytest.empty_queue() return b @pytest.fixture(autouse=True) @@ -26,4 +27,9 @@ def sort_cog(bot: commands.Bot): async def test_sort(): await dpytest.message("!sort house dog") msg = dpytest.sent_queue.peek() - assert dpytest.verify().message().content("2 arguments: dog house"), msg.content \ No newline at end of file + assert dpytest.verify().message().content("2 arguments: dog house"), msg.content + +@pytest.mark.asyncio +async def test_sort_no_params(): + await dpytest.message("!sort") + assert dpytest.verify().message().content("No arguments found.") \ No newline at end of file From c1afb0d00c156e11a383b55fb72a442ac4baf7d9 Mon Sep 17 00:00:00 2001 From: abluey Date: Thu, 22 Jul 2021 22:28:18 +0800 Subject: [PATCH 30/30] Can look up tweets from twitter usernames! --- Zoe/cogs/inventory.py | 185 ++++++++++++++++++++++++++++++++++++++++++ Zoe/cogs/twitter.py | 54 ++++++++++++ Zoe/main.py | 8 ++ Zoe/requirements.txt | 3 +- 4 files changed, 249 insertions(+), 1 deletion(-) create mode 100644 Zoe/cogs/inventory.py create mode 100644 Zoe/cogs/twitter.py diff --git a/Zoe/cogs/inventory.py b/Zoe/cogs/inventory.py new file mode 100644 index 0000000..5d7fc43 --- /dev/null +++ b/Zoe/cogs/inventory.py @@ -0,0 +1,185 @@ +import sqlite3 +import discord +from discord.ext import commands +import datetime + + +# for reference :) +# import datetime +# datetime.datetime.now().strftime("%d-%m-%Y") +# outputs date in dd-mm-YYYY, a string + + +class InventoryCog(commands.Cog): + + def __init__(self, bot): + self.bot = bot + self.con = sqlite3.connect('inventory.db') + self.cur = self.con.cursor() + + # Create tables + self.cur.execute('''CREATE TABLE IF NOT EXISTS Items ( + ItemID integer PRIMARY KEY AUTOINCREMENT, + ItemName varchar(255), + ItemDesc varchar(255), + Amount integer + );''' + ) + + + self.cur.execute('''CREATE TABLE IF NOT EXISTS Checkout ( + CheckoutID integer PRIMARY KEY AUTOINCREMENT, + User varchar(255), + TakenAmount integer, + TakenDate varchar(10), + ItemID integer, + CONSTRAINT fk_extensions + FOREIGN KEY (ItemID) + REFERENCES Items (ItemID) + );''' + ) + self.con.commit() + + # Inserting values into ITEMS + self.cur.executescript('''INSERT INTO Items ( ItemName, ItemDesc, Amount) VALUES + ( "Headphones", "Pair of headphones", 10); + INSERT INTO Items (ItemName, ItemDesc, Amount) VALUES + ("Mice", "Mice not sure what you expect", 5); + INSERT INTO Items (ItemName, ItemDesc, Amount) VALUES + ("Keyboard", "Goes click click click", 6); + INSERT INTO Items (ItemName, ItemDesc, Amount) VALUES + ("Computer", "Has input + output and sometimes runs", 10); + INSERT INTO Items (ItemName, ItemDesc, Amount) VALUES + ("Mousemat", "Flat thing to put mouse on", 4);''') + self.con.commit() + + # Inserting values into CHECKOUT + self.cur.executescript('''INSERT INTO Checkout ( User, TakenAmount, TakenDate, ItemID) VALUES + ( "A", 2, "14-07-21", 1); + INSERT INTO Checkout (User, TakenAmount, TakenDate, ItemID) VALUES + ("B", 8, "14-07-21", 1); + INSERT INTO Checkout (User, TakenAmount, TakenDate, ItemID) VALUES + ("B", 2, "13-07-21", 2); + INSERT INTO Checkout (User, TakenAmount, TakenDate, ItemID) VALUES + ("D", 1, "14-07-21", 2); + INSERT INTO Checkout (User, TakenAmount, TakenDate, ItemID) VALUES + ("A", 3, "14-07-21", 3); + INSERT INTO Checkout (User, TakenAmount, TakenDate, ItemID) VALUES + ("C", 6, "13-07-21", 4); + INSERT INTO Checkout (User, TakenAmount, TakenDate, ItemID) VALUES + ("A", 1, "14-07-21", 4); + INSERT INTO Checkout (User, TakenAmount, TakenDate, ItemID) VALUES + ("D", 4, "14-07-21", 5); + ''') + + self.con.commit() + + + #Checkout item (almost completed) + ''' + Arg 1: item id + Arg 2: amount + ''' + @commands.command() + async def checkout(self, cxt,*args): + if cxt.author == self.bot.user: + return + else: + itemId = int(args[0]) + amount = int(args[1]) + + #Should check to see if the item exists + total = self.cur.execute('SELECT Amount FROM Items WHERE ItemID = (?)', (str(itemId))) + + #Check to see if the item exists + if self.cur.fetchone() == None: + await cxt.send("The guild doesn't currently have that item") + + elif (0 < amount): + await cxt.send("You're trying to checkout negative/no items?!") + + elif(amount <= total): + checkedOut = self.cur.execute('''INSERT INTO Checkout (User, TakenAmount,ItemID) + (?,?,?) + ''', (cxt.message.author.id, amount, itemId)) + updateAmount = self.cur.execute('''UPDATE Items + SET Amount = (?) + WHERE ItemID = (?)''', (total - amount, itemId)) + + await cxt.send("User "+ cxt.author + " successfully checked out " + amount + " of item " + itemId) + + else: + await cxt.send("The guild doesn't currently have that item in stock") + + + # SHOULD work??? + #Return item + @commands.command() + async def return_item(self, cxt,*args): + if cxt.author == self.bot.user: + return + else: + itemId = int(args[0]) + amount = int(args[1]) + + # Gets the CheckoutID and amount that was checked out + checkoutId = self.cur.execute('SELECT CheckoutID FROM Checkout WHERE User = (?) AND ItemID = (?)', (cxt.message.author.id, itemId)) + takenAmount = self.cur.execute('SELECT TakenAmount FROM Checkout WHERE User = (?)', (cxt.message.author.id)) + + if (amount == 0): + await cxt.send("Why are you returning 0 items? Is this a joke?") + + # user is returning something + else: + if (takenAmount == amount): + self.cur.execute('DELETE FROM Checkout WHERE CheckoutID = (?)', (checkoutId)) + await cxt.send("All items returned. Checkout entry {0} deleted from table.".format(checkoutId)) + + elif (0 < takenAmount < amount): + self.cur.execute('UPDATE Checkout SET TakenAmount = (?) WHERE CheckoutID = (?)', (takenAmount - amount), (checkoutId)) + await cxt.send("Some items returned. Checkout entry {0} updated.".format(checkoutId)) + + # if user is returning a negative value + else: + await cxt.send("If you want to borrow more items, please use !checkout.") + + + + #View checked out items (completed) + @commands.command() + async def view_checkouts(self, cxt): + if cxt.author == self.bot.user: + return + else: + allCheckedOut = self.cur.execute('SELECT * FROM Checkout') + for row in allCheckedOut: + await cxt.send(row) + + + #View instock + @commands.command() + async def view_stock(self, cxt,*args): + if cxt.author == self.bot.user: + return + else: + inStock = self.cur.execute('SELECT * FROM Items WHERE Amount != 0') + for row in inStock: + await cxt.send(row) + + + #Search society items + @commands.command() + async def search(self, cxt,*args): + if cxt.author == self.bot.user: + return + else: + searchString = args[0] + result = self.cur.execute('SELECT * FROM Items WHERE ItemName = (?)', (searchString)) + if (self.cur.fetchone() == None): + await cxt.send("The guild does not have an item with that name") + else: + for row in result: + await cxt.send(row) + +def setup(bot): + bot.add_cog(InventoryCog(bot)) \ No newline at end of file diff --git a/Zoe/cogs/twitter.py b/Zoe/cogs/twitter.py new file mode 100644 index 0000000..9be0afe --- /dev/null +++ b/Zoe/cogs/twitter.py @@ -0,0 +1,54 @@ +import os +import requests +import json + +import discord +from discord.ext import commands + +class Twitter(commands.Cog): + + def __init__(self, bot): + self.bot = bot + self.apiKey = os.environ['KOALA_API_KEY'] + self.apiSecret = os.environ['KOALA_SECRET_KEY'] + self.accessToken = os.environ['KOALA_ACCESS'] + self.accessSecret = os.environ['KOALA_ACCESS_SECRET'] + self.bearerToken = os.environ['KOALA_BEARER'] + + # def create_url(): + # return "https://api.twitter.com/2/users/1415763208477020163/tweets" + + # def get_params(): + # return {"tweets.fields":"created_at"} + + def bearer_oauth(self, r): + r.headers["Authorization"] = f"Bearer {self.bearerToken}" + r.headers["User-Agent"] = "v2UserTweetsPython" + return r + + @commands.command() + async def get_tweet(self, ctx, user): + + try: + userIDResponse = requests.request("GET", "https://api.twitter.com/2/users/by/username/{}".format(user), auth=self.bearer_oauth, params="") + userResponseJson = userIDResponse.json() + userID = userResponseJson["data"]["id"] + + response = requests.request("GET", "https://api.twitter.com/2/users/{}/tweets".format(userID), auth=self.bearer_oauth, params="") + json_response = response.json() + + url = "https://twitter.com/i/web/status/{}".format(json_response["data"][0]["id"]) + description = json_response["data"][0]["text"] + + username = userResponseJson["data"]["username"] + + embed = discord.Embed(title="{}'s last tweet".format(username), description=description, url=url) + + await ctx.send(embed=embed) + + except: + await ctx.send(":(") + + +def setup(bot): + bot.add_cog(Twitter(bot)) \ No newline at end of file diff --git a/Zoe/main.py b/Zoe/main.py index 881b156..0d1acd6 100644 --- a/Zoe/main.py +++ b/Zoe/main.py @@ -12,6 +12,7 @@ async def on_ready(): bot.load_extension("cogs.greetings") bot.load_extension("cogs.sort") bot.load_extension("cogs.random") + bot.load_extension("cogs.twitter") @bot.event @@ -31,6 +32,13 @@ async def on_message(msg): await bot.process_commands(msg) +#command errors +@bot.event +async def on_command_error(ctx, error): + if isinstance(error, commands.MissingRequiredArgument): + await ctx.send("Missing argument.") + + load_dotenv() BOT_TOKEN=os.environ['TOKEN'] bot.run(BOT_TOKEN) \ No newline at end of file diff --git a/Zoe/requirements.txt b/Zoe/requirements.txt index 557f2eb..9ca5d0d 100644 --- a/Zoe/requirements.txt +++ b/Zoe/requirements.txt @@ -1,4 +1,5 @@ discord.py==1.7.3 dpytest==0.5.3 pytest==6.2.4 -python-dotenv==0.18.0 \ No newline at end of file +python-dotenv==0.18.0 +TwitterAPI==2.7.5 \ No newline at end of file