From 336c3f7655f236cdbeb79e93ecb12bc488fbe0c9 Mon Sep 17 00:00:00 2001 From: Mark Hoekveen Date: Tue, 25 Oct 2022 19:39:02 +0200 Subject: [PATCH 1/6] fix initial async errors --- Points.py | 1 + Stroopwafel.py | 26 ++++++++++++-------------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/Points.py b/Points.py index 564f190..280ae5a 100644 --- a/Points.py +++ b/Points.py @@ -15,6 +15,7 @@ class Points(commands.Cog): self.voice_states = {} self.BANK_ID = 42 + self.init() def __check(self, ctx): return True diff --git a/Stroopwafel.py b/Stroopwafel.py index 1086b15..b6e4120 100644 --- a/Stroopwafel.py +++ b/Stroopwafel.py @@ -15,7 +15,15 @@ from discord.ext import commands logging.basicConfig(level=logging.INFO) -bot = commands.Bot(command_prefix=commands.when_mentioned_or('!'), description='Stroopwafel. Shitpost bot extraordinaire.', pm_help=True) +async def add_cogs(bot): + await bot.add_cog(Shitpost.Shitpost(bot)) + await bot.add_cog(General.General(bot)) + await bot.add_cog(Cryptocoin.Cryptocoin(bot)) + await bot.add_cog(Chatbot.Chatbot(bot)) + await bot.add_cog(Points.Points(bot)) + + +bot = commands.Bot(command_prefix=commands.when_mentioned_or('!'), description='Stroopwafel. Shitpost bot extraordinaire.', pm_help=True, intents=discord.Intents.default()) #Read configuration file: config = configparser.ConfigParser() @@ -24,6 +32,7 @@ bot.tokens = config["tokens"] bot.hdChannels = {} for channel in config["channels"]: #channelIDs must be integers bot.hdChannels[channel] = int(config["channels"][channel]) + #passwords are base64 encoded, which makes it like 1% safer bot.passwords = {} for pw in config["passwords"]: @@ -33,20 +42,9 @@ for pw in config["passwords"]: print("Problem with decoding password!") bot.passwords[pw] = config["passwords"][pw] -#bot.add_cog(Music.Music(bot)) -#TODO: Re-add music functions now that we require a stronger host -bot.add_cog(Shitpost.Shitpost(bot)) -bot.add_cog(General.General(bot)) -bot.add_cog(Cryptocoin.Cryptocoin(bot)) -bot.add_cog(Chatbot.Chatbot(bot)) -pointsBot = Points.Points(bot) -bot.add_cog(pointsBot) - @bot.event -@asyncio.coroutine -def on_ready(): +async def on_ready(): + await add_cogs(bot) print('Logged in as:\n{0} (ID: {0.id})'.format(bot.user)) - #TODO: find out how to do this properly: - pointsBot.init() bot.run(bot.tokens["discordbot"]) From fe638f58775cefcee3f81ff34b75342cee230a81 Mon Sep 17 00:00:00 2001 From: Mark Hoekveen Date: Tue, 25 Oct 2022 20:06:41 +0200 Subject: [PATCH 2/6] juiste permissions/intents --- Stroopwafel.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Stroopwafel.py b/Stroopwafel.py index b6e4120..e90c8c9 100644 --- a/Stroopwafel.py +++ b/Stroopwafel.py @@ -22,8 +22,10 @@ async def add_cogs(bot): await bot.add_cog(Chatbot.Chatbot(bot)) await bot.add_cog(Points.Points(bot)) +intents = discord.Intents.default() +intents.message_content = True -bot = commands.Bot(command_prefix=commands.when_mentioned_or('!'), description='Stroopwafel. Shitpost bot extraordinaire.', pm_help=True, intents=discord.Intents.default()) +bot = commands.Bot(command_prefix=commands.when_mentioned_or('!'), description='Stroopwafel. Shitpost bot extraordinaire.', pm_help=True, intents=intents) #Read configuration file: config = configparser.ConfigParser() From e7284d2c2811e35fc37c162c989a46426b2d9eb2 Mon Sep 17 00:00:00 2001 From: Mark Hoekveen Date: Tue, 25 Oct 2022 22:39:58 +0200 Subject: [PATCH 3/6] Members intent --- Stroopwafel.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Stroopwafel.py b/Stroopwafel.py index e90c8c9..43807a8 100644 --- a/Stroopwafel.py +++ b/Stroopwafel.py @@ -24,6 +24,7 @@ async def add_cogs(bot): intents = discord.Intents.default() intents.message_content = True +intents.members = True bot = commands.Bot(command_prefix=commands.when_mentioned_or('!'), description='Stroopwafel. Shitpost bot extraordinaire.', pm_help=True, intents=intents) From 9512b9dc86ce1f5be54fcb68f66fd6f38425b1d5 Mon Sep 17 00:00:00 2001 From: Mark Hoekveen Date: Tue, 25 Oct 2022 22:40:26 +0200 Subject: [PATCH 4/6] Fix lokale testbug als kanaal niet bestaat --- Points.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Points.py b/Points.py index 280ae5a..934d18b 100644 --- a/Points.py +++ b/Points.py @@ -264,7 +264,8 @@ class Points(commands.Cog): np.save("pointscount.npy", pointsCount) # Add new/unknown members: - memberList = self.bot.get_channel(self.bot.hdChannels["shitpost"]).members + list_channel = self.bot.get_channel(self.bot.hdChannels["shitpost"]) + memberList = list_channel.members if list_channel else [] for member in memberList: # Give new members 100 points if member.id not in pointsCount.keys() and not member.bot: From 9665a52d231391b876bfbac40ef15a45e608783e Mon Sep 17 00:00:00 2001 From: Mark Hoekveen Date: Tue, 25 Oct 2022 22:51:17 +0200 Subject: [PATCH 5/6] houd rekening met async iterators --- Chatbot.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Chatbot.py b/Chatbot.py index 9d83b66..3a3f21d 100644 --- a/Chatbot.py +++ b/Chatbot.py @@ -207,7 +207,7 @@ class Chatbot(commands.Cog): messageIterator = channel.history(limit=nrOfMessages, before=None, after=None, oldest_first=False, around=None) allMessages = [] for i in range(nrOfMessages): - msg = yield from messageIterator.next() + msg = yield from anext(messageIterator) allMessages.append(msg) i = 0 @@ -256,10 +256,10 @@ class Chatbot(commands.Cog): #Get previous message to respond to messageIterator = ctx.channel.history(limit=3, before=None, after=None, oldest_first=False, around=None) - messageToRespondTo = yield from messageIterator.next() #this will be the !reageer command. skip - messageToRespondTo = yield from messageIterator.next() + messageToRespondTo = yield from anext(messageIterator) #this will be the !reageer command. skip + messageToRespondTo = yield from anext(messageIterator) if messageToRespondTo.content.strip()[0] == '!' or messageToRespondTo.author.bot: #another chance - messageToRespondTo = yield from messageIterator.next() #but it's not a huge problem if he responds to himself + messageToRespondTo = yield from anext(messageIterator) #but it's not a huge problem if he responds to himself if messageToRespondTo.content.strip()[0] == '!': wordsToRespondTo = [] else: From f0975cef52c2f41de9751a5c79606395c73290c3 Mon Sep 17 00:00:00 2001 From: Jan-Paul van Osta Date: Wed, 2 Nov 2022 22:20:19 +0100 Subject: [PATCH 6/6] documenteren kan je leren --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 3f28ba3..0203486 100644 --- a/README.md +++ b/README.md @@ -25,5 +25,6 @@ Requirements: * `numpy` * `youtube_dl` * `ffmpeg-python` +* `caldav` Verder zoek je het zelf maar uit. \ No newline at end of file