From 015730f74fec1abdabbdbfb63db4226b24e17b1b Mon Sep 17 00:00:00 2001 From: nosf Date: Sun, 27 Jun 2021 22:08:53 -0300 Subject: [PATCH 01/17] --- cogs/Rent.py | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 cogs/Rent.py diff --git a/cogs/Rent.py b/cogs/Rent.py new file mode 100644 index 0000000..088a080 --- /dev/null +++ b/cogs/Rent.py @@ -0,0 +1,70 @@ +from discord.ext import tasks, commands +from discord.utils import get +from util import * + + +import pymongo +from config import MONGODB_ATLAS_URI +from config import CHANNEL_ID + +import time + +class Rent(commands.Cog): + def __init__(self, bot): + self.bot = bot + + self.time_expired.start() + + client = pymongo.MongoClient(MONGODB_ATLAS_URI) + self.db = client['discord-bot']['discord-bot'] + self.rent = self.db.find_one({"description": "rent"})['rent'] + self.time = self.db.find_one({"description": "rent"})['rent_time'] + + #A function to register the rent of a beaglebone black for 12 hours + @commands.command(brief='Uma função para alugar a beaglebone black de maíra canal (gerente do alto nível)' + help='Use o comando >alugar para ter acesso irrestrito durante doze horas a uma beaglebone black, caso alguém já esteja de posse dela você será avisado/avisada', + aliases=['aluguel','beaglebone','aluga']) + async def alugar(self, ctx): + await ctx.trigger_typing() + + print(f '\n [*] \'>alugar\' command called.') + + if not self.db.find_one({"description": "rent"})['rent']: + self.db.update({"description": "rent"},{"$set":{"rent": ctx.message.author.id}}) + self.db.update({"description": "rent"},{"$set":{"rent_time": time.time()/3600}}) + await ctx.send(f'A beaglebone foi alugada com sucesso por `{ctx.author.mention}`, por doze horas a beaglebone estará sobre sua posse') + else: + await ctx.send(f'A beaglebone já foi alugada por <@`{self.rent}`>, entre em contato com ela/ele ou aguarde o tempo de devolução') + await reactToMessage(self.bot, ctx.message, [MESSAGE_EMOJI]) + + #A function to return the beaglebone black before 12 hours of usage + @commands.command(brief='Uma função para devolver a beagleboneblack caso ja tenha sido alugada', + help='Use o comando devolver só quando estiver empossado/empossada da beagleboneblack a fim de devolver ela para o grupo', + aliases=['devolução','desalugar','desaluga','aluga','beaglebone']) + async def devolver(self, ctx): + await ctx.trigger_typing() + + print(f '\n [*] \'>devolver\' command called.') + + if ctx.message.author != self.rent: + await ctx.send(f'Você não está de posse da beaglebone, alugue usando `>alugar` caso ela esteja livre') + else: + self.db.update({"description": "rent"}, {"$set":{"rent": None}}) + await ctx.send(f'A beaglebone foi devolvida, obrigado `{ctx.author.mention}`') + await reactToMessage(self.bot, ctx.message, [MESSAGE_EMOJI]) + + + @tasks.loop(minutes=10) + async def time_expired(self): + if time.time()/3600 - self.time >= 12: + txt = (f'O tempo de uso da beaglebone expirou <@`{self.rent}`>, alugue-a novamente caso não existam solicitações de aluguel anteriores') + channel = await self.bot.fetch_channel(CHANNEL_ID) + await channel.send(context=txt) + self.db.update({"description": "rent"}, {"$set":{"rent": None}}) + +def setup(bot): + bot.add_cog(Rent(bot)) + + + + From 926d73cb98a30b05214eb8d38088fe7679095d50 Mon Sep 17 00:00:00 2001 From: nosf Date: Wed, 30 Jun 2021 18:42:57 -0300 Subject: [PATCH 02/17] micro corrections of syntax --- cogs/Rent.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cogs/Rent.py b/cogs/Rent.py index 088a080..16d4804 100644 --- a/cogs/Rent.py +++ b/cogs/Rent.py @@ -20,8 +20,8 @@ def __init__(self, bot): self.rent = self.db.find_one({"description": "rent"})['rent'] self.time = self.db.find_one({"description": "rent"})['rent_time'] - #A function to register the rent of a beaglebone black for 12 hours - @commands.command(brief='Uma função para alugar a beaglebone black de maíra canal (gerente do alto nível)' + #A function to register the rent of a beaglebone black for 2 hours + @commands.command(brief='Uma função para alugar a beaglebone black de maíra canal (gerente do alto nível)', help='Use o comando >alugar para ter acesso irrestrito durante doze horas a uma beaglebone black, caso alguém já esteja de posse dela você será avisado/avisada', aliases=['aluguel','beaglebone','aluga']) async def alugar(self, ctx): @@ -37,7 +37,7 @@ async def alugar(self, ctx): await ctx.send(f'A beaglebone já foi alugada por <@`{self.rent}`>, entre em contato com ela/ele ou aguarde o tempo de devolução') await reactToMessage(self.bot, ctx.message, [MESSAGE_EMOJI]) - #A function to return the beaglebone black before 12 hours of usage + #A function to return the beaglebone black before 2 hours of usage @commands.command(brief='Uma função para devolver a beagleboneblack caso ja tenha sido alugada', help='Use o comando devolver só quando estiver empossado/empossada da beagleboneblack a fim de devolver ela para o grupo', aliases=['devolução','desalugar','desaluga','aluga','beaglebone']) @@ -46,7 +46,7 @@ async def devolver(self, ctx): print(f '\n [*] \'>devolver\' command called.') - if ctx.message.author != self.rent: + if ctx.message.author.id != self.rent: await ctx.send(f'Você não está de posse da beaglebone, alugue usando `>alugar` caso ela esteja livre') else: self.db.update({"description": "rent"}, {"$set":{"rent": None}}) @@ -56,7 +56,7 @@ async def devolver(self, ctx): @tasks.loop(minutes=10) async def time_expired(self): - if time.time()/3600 - self.time >= 12: + if time.time()/3600 - self.time >= 2: txt = (f'O tempo de uso da beaglebone expirou <@`{self.rent}`>, alugue-a novamente caso não existam solicitações de aluguel anteriores') channel = await self.bot.fetch_channel(CHANNEL_ID) await channel.send(context=txt) From 2c3eb325a3ddc8d06322189753f03158c6b70271 Mon Sep 17 00:00:00 2001 From: mairacanal Date: Thu, 1 Jul 2021 08:09:38 -0300 Subject: [PATCH 03/17] Adding Rent to main cog list --- cogs/Rent.py | 35 ++++++++++++++++------------------- util.py | 3 +-- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/cogs/Rent.py b/cogs/Rent.py index 16d4804..4f9e29c 100644 --- a/cogs/Rent.py +++ b/cogs/Rent.py @@ -1,8 +1,6 @@ from discord.ext import tasks, commands -from discord.utils import get from util import * - import pymongo from config import MONGODB_ATLAS_URI from config import CHANNEL_ID @@ -12,39 +10,41 @@ class Rent(commands.Cog): def __init__(self, bot): self.bot = bot - + self.time_expired.start() - + client = pymongo.MongoClient(MONGODB_ATLAS_URI) self.db = client['discord-bot']['discord-bot'] self.rent = self.db.find_one({"description": "rent"})['rent'] self.time = self.db.find_one({"description": "rent"})['rent_time'] #A function to register the rent of a beaglebone black for 2 hours - @commands.command(brief='Uma função para alugar a beaglebone black de maíra canal (gerente do alto nível)', - help='Use o comando >alugar para ter acesso irrestrito durante doze horas a uma beaglebone black, caso alguém já esteja de posse dela você será avisado/avisada', - aliases=['aluguel','beaglebone','aluga']) + @commands.command( + brief='Uma função para alugar a Beaglebone Black de Maíra Canal (gerente do alto nível)', + help='Use o comando >alugar para ter acesso irrestrito durante duas horas a uma Beaglebone Black. Caso alguém já esteja de posse dela, você será avisado/avisada', + aliases=['aluguel','beaglebone','aluga']) async def alugar(self, ctx): await ctx.trigger_typing() - print(f '\n [*] \'>alugar\' command called.') + print(f'\n [*] \'>alugar\' command called.') if not self.db.find_one({"description": "rent"})['rent']: self.db.update({"description": "rent"},{"$set":{"rent": ctx.message.author.id}}) self.db.update({"description": "rent"},{"$set":{"rent_time": time.time()/3600}}) - await ctx.send(f'A beaglebone foi alugada com sucesso por `{ctx.author.mention}`, por doze horas a beaglebone estará sobre sua posse') + await ctx.send(f'A Beaglebone foi alugada com sucesso por `{ctx.author.mention}`, por duas horas a Beaglebone Black estará sobre sua posse') else: - await ctx.send(f'A beaglebone já foi alugada por <@`{self.rent}`>, entre em contato com ela/ele ou aguarde o tempo de devolução') + await ctx.send(f'A Beaglebone já foi alugada por <@`{self.rent}`>, entre em contato com ela/ele ou aguarde o tempo de devolução') await reactToMessage(self.bot, ctx.message, [MESSAGE_EMOJI]) #A function to return the beaglebone black before 2 hours of usage - @commands.command(brief='Uma função para devolver a beagleboneblack caso ja tenha sido alugada', - help='Use o comando devolver só quando estiver empossado/empossada da beagleboneblack a fim de devolver ela para o grupo', - aliases=['devolução','desalugar','desaluga','aluga','beaglebone']) + @commands.command( + brief='Uma função para devolver a beagleboneblack caso ja tenha sido alugada', + help='Use o comando devolver só quando estiver empossado/empossada da Beaglebone Black a fim de devolver ela para o grupo', + aliases=['devolução','desalugar','desaluga','aluga','beaglebone']) async def devolver(self, ctx): await ctx.trigger_typing() - print(f '\n [*] \'>devolver\' command called.') + print(f'\n [*] \'>devolver\' command called.') if ctx.message.author.id != self.rent: await ctx.send(f'Você não está de posse da beaglebone, alugue usando `>alugar` caso ela esteja livre') @@ -54,17 +54,14 @@ async def devolver(self, ctx): await reactToMessage(self.bot, ctx.message, [MESSAGE_EMOJI]) - @tasks.loop(minutes=10) + @tasks.loop(minutes = 10) async def time_expired(self): if time.time()/3600 - self.time >= 2: - txt = (f'O tempo de uso da beaglebone expirou <@`{self.rent}`>, alugue-a novamente caso não existam solicitações de aluguel anteriores') + txt = (f'O tempo de uso da beaglebone expirou <@`{self.rent}`>. Alugue-a novamente caso não existam solicitações de aluguel anteriores.') channel = await self.bot.fetch_channel(CHANNEL_ID) await channel.send(context=txt) self.db.update({"description": "rent"}, {"$set":{"rent": None}}) def setup(bot): bot.add_cog(Rent(bot)) - - - diff --git a/util.py b/util.py index a5a98fa..e047bbe 100644 --- a/util.py +++ b/util.py @@ -2,7 +2,6 @@ import re from functools import reduce import requests -from bs4 import BeautifulSoup # constants WELCOME_CHANNEL = 'random' # channel in which to send welcome message for new members @@ -10,7 +9,7 @@ RESPONSE_EMOJI = '🚚' # emoji that'll be used to react to all bot messages FIXED_COGS = [ # all cogs that aren't from the google sheet 'Reuniões', 'OnMemberJoin', 'Decisions', - 'Counters', 'Utilities', 'Birthday' + 'Counters', 'Utilities', 'Birthday', 'Rent' ] AVAILABLE_REACTIONS = [ # list of reactions that'll be used in poll-like commands '🤠', '🍉', '💘', '🏂', From 43673004188df33d0ece7fad7c5db5961a767458 Mon Sep 17 00:00:00 2001 From: mairacanal Date: Thu, 1 Jul 2021 08:27:56 -0300 Subject: [PATCH 04/17] Improving code at Rent.py --- cogs/Counters.py | 6 ++---- cogs/Rent.py | 36 +++++++++++++++++++++--------------- util.py | 7 ++++--- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/cogs/Counters.py b/cogs/Counters.py index 1562c6b..61c62dd 100644 --- a/cogs/Counters.py +++ b/cogs/Counters.py @@ -1,6 +1,5 @@ import pymongo from discord.ext import commands -from discord.utils import get from util import * from config import MONGODB_ATLAS_URI @@ -17,10 +16,9 @@ def __init__(self, bot): @commands.command(brief='', help='', aliases=[]) async def júlio(self, ctx): await ctx.trigger_typing() - channel = ctx.channel print(f'\n [*] \'>júlio\' command called.') - + await reactToMessage(self.bot, ctx.message, [MESSAGE_EMOJI]) # increments that counter and saves it to the db @@ -46,7 +44,7 @@ async def bap(self, ctx): response = await ctx.send(f'*Leonardo* ||Baptistella||, foi preso `{self.counters["bap"]}` vezes.') - await reactToResponse(self.bot, response, ['🔒']) + await reactToResponse(self.bot, response, ['🔒']) def setup(bot): bot.add_cog(Counters(bot)) diff --git a/cogs/Rent.py b/cogs/Rent.py index 4f9e29c..c7825ec 100644 --- a/cogs/Rent.py +++ b/cogs/Rent.py @@ -1,16 +1,14 @@ +import pymongo from discord.ext import tasks, commands from util import * - -import pymongo from config import MONGODB_ATLAS_URI from config import CHANNEL_ID -import time +from time import time class Rent(commands.Cog): def __init__(self, bot): self.bot = bot - self.time_expired.start() client = pymongo.MongoClient(MONGODB_ATLAS_URI) @@ -20,43 +18,51 @@ def __init__(self, bot): #A function to register the rent of a beaglebone black for 2 hours @commands.command( - brief='Uma função para alugar a Beaglebone Black de Maíra Canal (gerente do alto nível)', + brief='Uma função para alugar a Beaglebone Black de Maíra Canal (gerente do Alto Nível)', help='Use o comando >alugar para ter acesso irrestrito durante duas horas a uma Beaglebone Black. Caso alguém já esteja de posse dela, você será avisado/avisada', - aliases=['aluguel','beaglebone','aluga']) + aliases=['aluguel','beaglebone','aluga'] + ) async def alugar(self, ctx): await ctx.trigger_typing() print(f'\n [*] \'>alugar\' command called.') + await reactToMessage(self.bot, ctx.message, [MESSAGE_EMOJI]) + if not self.db.find_one({"description": "rent"})['rent']: self.db.update({"description": "rent"},{"$set":{"rent": ctx.message.author.id}}) - self.db.update({"description": "rent"},{"$set":{"rent_time": time.time()/3600}}) - await ctx.send(f'A Beaglebone foi alugada com sucesso por `{ctx.author.mention}`, por duas horas a Beaglebone Black estará sobre sua posse') + self.db.update({"description": "rent"},{"$set":{"rent_time": time()/3600}}) + response = await ctx.send(f'A Beaglebone foi alugada com sucesso por `{ctx.author.mention}`, por duas horas a Beaglebone Black estará sobre sua posse') else: - await ctx.send(f'A Beaglebone já foi alugada por <@`{self.rent}`>, entre em contato com ela/ele ou aguarde o tempo de devolução') - await reactToMessage(self.bot, ctx.message, [MESSAGE_EMOJI]) + response = await ctx.send(f'A Beaglebone já foi alugada por <@`{self.rent}`>, entre em contato com ela/ele ou aguarde o tempo de devolução') + + await reactToResponse(self.bot, response, [MESSAGE_EMOJI]) #A function to return the beaglebone black before 2 hours of usage @commands.command( brief='Uma função para devolver a beagleboneblack caso ja tenha sido alugada', help='Use o comando devolver só quando estiver empossado/empossada da Beaglebone Black a fim de devolver ela para o grupo', - aliases=['devolução','desalugar','desaluga','aluga','beaglebone']) + aliases=['devolução','desalugar','desaluga','aluga','beaglebone'] + ) async def devolver(self, ctx): await ctx.trigger_typing() print(f'\n [*] \'>devolver\' command called.') + await reactToMessage(self.bot, ctx.message, [MESSAGE_EMOJI]) + if ctx.message.author.id != self.rent: - await ctx.send(f'Você não está de posse da beaglebone, alugue usando `>alugar` caso ela esteja livre') + response = await ctx.send(f'Você não está de posse da Beaglebone. Alugue usando `>alugar` caso ela esteja livre.') else: self.db.update({"description": "rent"}, {"$set":{"rent": None}}) - await ctx.send(f'A beaglebone foi devolvida, obrigado `{ctx.author.mention}`') - await reactToMessage(self.bot, ctx.message, [MESSAGE_EMOJI]) + response = await ctx.send(f'A Beaglebone foi devolvida. Obrigado `{ctx.author.mention}`!') + + await reactToResponse(self.bot, response, [MESSAGE_EMOJI]) @tasks.loop(minutes = 10) async def time_expired(self): - if time.time()/3600 - self.time >= 2: + if time()/3600 - self.time >= 2: txt = (f'O tempo de uso da beaglebone expirou <@`{self.rent}`>. Alugue-a novamente caso não existam solicitações de aluguel anteriores.') channel = await self.bot.fetch_channel(CHANNEL_ID) await channel.send(context=txt) diff --git a/util.py b/util.py index e047bbe..df2aeeb 100644 --- a/util.py +++ b/util.py @@ -9,7 +9,8 @@ RESPONSE_EMOJI = '🚚' # emoji that'll be used to react to all bot messages FIXED_COGS = [ # all cogs that aren't from the google sheet 'Reuniões', 'OnMemberJoin', 'Decisions', - 'Counters', 'Utilities', 'Birthday', 'Rent' + 'Counters', 'Utilities', 'Birthday', + 'Rent' ] AVAILABLE_REACTIONS = [ # list of reactions that'll be used in poll-like commands '🤠', '🍉', '💘', '🏂', @@ -25,7 +26,7 @@ 'querido', 'barbeiro', 'zé', 'filho' ] -async def reactToResponse(bot, response, emojiList = []): +async def reactToResponse(response, emojiList = []): if not emojiList: emojiList = [] emojiList.insert(0, RESPONSE_EMOJI) @@ -37,7 +38,7 @@ async def reactToResponse(bot, response, emojiList = []): else: print(f" [**] The reaction {emoji} was successfully added to the response.") -async def reactToMessage(bot, message, emojiList: list): +async def reactToMessage(message, emojiList: list): for emoji in emojiList: try: await message.add_reaction(emoji) From e5fb936354d28c5f5760e63ab93ff04111077a15 Mon Sep 17 00:00:00 2001 From: mairacanal Date: Thu, 1 Jul 2021 08:40:33 -0300 Subject: [PATCH 05/17] Adjusting the MongoDB document --- cogs/Rent.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cogs/Rent.py b/cogs/Rent.py index c7825ec..b21be1d 100644 --- a/cogs/Rent.py +++ b/cogs/Rent.py @@ -13,8 +13,8 @@ def __init__(self, bot): client = pymongo.MongoClient(MONGODB_ATLAS_URI) self.db = client['discord-bot']['discord-bot'] - self.rent = self.db.find_one({"description": "rent"})['rent'] - self.time = self.db.find_one({"description": "rent"})['rent_time'] + self.rent = self.db.find_one({"description": "rent"})['rent']['rent'] + self.time = self.db.find_one({"description": "rent"})['rent']['rent_time'] #A function to register the rent of a beaglebone black for 2 hours @commands.command( From 577df41d39a6fc1c49f6081313b89b43036e0e95 Mon Sep 17 00:00:00 2001 From: mairacanal Date: Thu, 1 Jul 2021 08:43:05 -0300 Subject: [PATCH 06/17] Removing repeting alias at rent.py --- cogs/Rent.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cogs/Rent.py b/cogs/Rent.py index b21be1d..6c561ec 100644 --- a/cogs/Rent.py +++ b/cogs/Rent.py @@ -20,7 +20,7 @@ def __init__(self, bot): @commands.command( brief='Uma função para alugar a Beaglebone Black de Maíra Canal (gerente do Alto Nível)', help='Use o comando >alugar para ter acesso irrestrito durante duas horas a uma Beaglebone Black. Caso alguém já esteja de posse dela, você será avisado/avisada', - aliases=['aluguel','beaglebone','aluga'] + aliases=['aluguel','aluga'] ) async def alugar(self, ctx): await ctx.trigger_typing() @@ -42,7 +42,7 @@ async def alugar(self, ctx): @commands.command( brief='Uma função para devolver a beagleboneblack caso ja tenha sido alugada', help='Use o comando devolver só quando estiver empossado/empossada da Beaglebone Black a fim de devolver ela para o grupo', - aliases=['devolução','desalugar','desaluga','aluga','beaglebone'] + aliases=['devolução','desalugar','desaluga'] ) async def devolver(self, ctx): await ctx.trigger_typing() From a25f9a91f145158eef8b5d826a26b8ed40651238 Mon Sep 17 00:00:00 2001 From: mairacanal Date: Thu, 1 Jul 2021 08:47:07 -0300 Subject: [PATCH 07/17] Fixing mispelling at rent.py --- cogs/Rent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cogs/Rent.py b/cogs/Rent.py index 6c561ec..b3afda6 100644 --- a/cogs/Rent.py +++ b/cogs/Rent.py @@ -65,7 +65,7 @@ async def time_expired(self): if time()/3600 - self.time >= 2: txt = (f'O tempo de uso da beaglebone expirou <@`{self.rent}`>. Alugue-a novamente caso não existam solicitações de aluguel anteriores.') channel = await self.bot.fetch_channel(CHANNEL_ID) - await channel.send(context=txt) + await channel.send(content=txt) self.db.update({"description": "rent"}, {"$set":{"rent": None}}) def setup(bot): From b41857bb9edf7c6a7d17178ed8c10030a82a7aed Mon Sep 17 00:00:00 2001 From: mairacanal Date: Thu, 1 Jul 2021 08:49:23 -0300 Subject: [PATCH 08/17] Adding legacy feature from the owner --- util.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util.py b/util.py index df2aeeb..38fe96d 100644 --- a/util.py +++ b/util.py @@ -26,7 +26,7 @@ 'querido', 'barbeiro', 'zé', 'filho' ] -async def reactToResponse(response, emojiList = []): +async def reactToResponse(bot, response, emojiList = []): if not emojiList: emojiList = [] emojiList.insert(0, RESPONSE_EMOJI) @@ -38,7 +38,7 @@ async def reactToResponse(response, emojiList = []): else: print(f" [**] The reaction {emoji} was successfully added to the response.") -async def reactToMessage(message, emojiList: list): +async def reactToMessage(bot, message, emojiList: list): for emoji in emojiList: try: await message.add_reaction(emoji) From e855a59ca6bc7adf9e7030c8fb463572b298e36f Mon Sep 17 00:00:00 2001 From: nosf Date: Fri, 2 Jul 2021 20:56:12 -0300 Subject: [PATCH 09/17] --- cogs/Rent.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/cogs/Rent.py b/cogs/Rent.py index b3afda6..c7b5c29 100644 --- a/cogs/Rent.py +++ b/cogs/Rent.py @@ -13,14 +13,14 @@ def __init__(self, bot): client = pymongo.MongoClient(MONGODB_ATLAS_URI) self.db = client['discord-bot']['discord-bot'] - self.rent = self.db.find_one({"description": "rent"})['rent']['rent'] - self.time = self.db.find_one({"description": "rent"})['rent']['rent_time'] + self.id = self.db.find_one({"description": "rent"})['discord_id'] + self.time = self.db.find_one({"description": "rent"})['rent_time'] #A function to register the rent of a beaglebone black for 2 hours @commands.command( brief='Uma função para alugar a Beaglebone Black de Maíra Canal (gerente do Alto Nível)', help='Use o comando >alugar para ter acesso irrestrito durante duas horas a uma Beaglebone Black. Caso alguém já esteja de posse dela, você será avisado/avisada', - aliases=['aluguel','aluga'] + aliases=['aluguel','aluga','alugar'] ) async def alugar(self, ctx): await ctx.trigger_typing() @@ -29,12 +29,12 @@ async def alugar(self, ctx): await reactToMessage(self.bot, ctx.message, [MESSAGE_EMOJI]) - if not self.db.find_one({"description": "rent"})['rent']: - self.db.update({"description": "rent"},{"$set":{"rent": ctx.message.author.id}}) - self.db.update({"description": "rent"},{"$set":{"rent_time": time()/3600}}) + if self.id == 0: + self.db.update_one({"description": "rent"},{"$set":{"discord_id": ctx.message.author.id}}) + self.db.update_one({"description": "rent"},{"$set":{"rent_time": time()/3600}}) response = await ctx.send(f'A Beaglebone foi alugada com sucesso por `{ctx.author.mention}`, por duas horas a Beaglebone Black estará sobre sua posse') else: - response = await ctx.send(f'A Beaglebone já foi alugada por <@`{self.rent}`>, entre em contato com ela/ele ou aguarde o tempo de devolução') + response = await ctx.send(f'A Beaglebone já foi alugada por <@`{self.id}`>, entre em contato com ela/ele ou aguarde o tempo de devolução') await reactToResponse(self.bot, response, [MESSAGE_EMOJI]) @@ -51,10 +51,10 @@ async def devolver(self, ctx): await reactToMessage(self.bot, ctx.message, [MESSAGE_EMOJI]) - if ctx.message.author.id != self.rent: + if ctx.message.author.id != self.id: response = await ctx.send(f'Você não está de posse da Beaglebone. Alugue usando `>alugar` caso ela esteja livre.') else: - self.db.update({"description": "rent"}, {"$set":{"rent": None}}) + self.db.update_one({"description": "rent"}, {"$set":{"discord_id": 0}}) response = await ctx.send(f'A Beaglebone foi devolvida. Obrigado `{ctx.author.mention}`!') await reactToResponse(self.bot, response, [MESSAGE_EMOJI]) @@ -63,10 +63,10 @@ async def devolver(self, ctx): @tasks.loop(minutes = 10) async def time_expired(self): if time()/3600 - self.time >= 2: - txt = (f'O tempo de uso da beaglebone expirou <@`{self.rent}`>. Alugue-a novamente caso não existam solicitações de aluguel anteriores.') + txt = (f'O tempo de uso da beaglebone expirou <@`{self.id}`>. Alugue-a novamente caso não existam solicitações de aluguel anteriores.') channel = await self.bot.fetch_channel(CHANNEL_ID) await channel.send(content=txt) - self.db.update({"description": "rent"}, {"$set":{"rent": None}}) + self.db.update({"description": "rent"}, {"$set":{"discord_id": 0}}) def setup(bot): bot.add_cog(Rent(bot)) From a58fb39b615bf924f7feb22a70cf9a5d4cfd87f9 Mon Sep 17 00:00:00 2001 From: nosf Date: Fri, 2 Jul 2021 21:00:17 -0300 Subject: [PATCH 10/17] --- cogs/Rent.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cogs/Rent.py b/cogs/Rent.py index c7b5c29..4f74b16 100644 --- a/cogs/Rent.py +++ b/cogs/Rent.py @@ -63,10 +63,11 @@ async def devolver(self, ctx): @tasks.loop(minutes = 10) async def time_expired(self): if time()/3600 - self.time >= 2: - txt = (f'O tempo de uso da beaglebone expirou <@`{self.id}`>. Alugue-a novamente caso não existam solicitações de aluguel anteriores.') - channel = await self.bot.fetch_channel(CHANNEL_ID) - await channel.send(content=txt) - self.db.update({"description": "rent"}, {"$set":{"discord_id": 0}}) + if self.id != 0 + txt = (f'O tempo de uso da beaglebone expirou <@`{self.id}`>. Alugue-a novamente caso não existam solicitações de aluguel anteriores.') + channel = await self.bot.fetch_channel(CHANNEL_ID) + await channel.send(content=txt) + self.db.update({"description": "rent"}, {"$set":{"discord_id": 0}}) def setup(bot): bot.add_cog(Rent(bot)) From 7b141b1b11bba05e2ee880537a10b36790f4c5bf Mon Sep 17 00:00:00 2001 From: nosf Date: Fri, 2 Jul 2021 21:54:01 -0300 Subject: [PATCH 11/17] --- cogs/Rent.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cogs/Rent.py b/cogs/Rent.py index 4f74b16..c9661d9 100644 --- a/cogs/Rent.py +++ b/cogs/Rent.py @@ -29,9 +29,9 @@ async def alugar(self, ctx): await reactToMessage(self.bot, ctx.message, [MESSAGE_EMOJI]) - if self.id == 0: - self.db.update_one({"description": "rent"},{"$set":{"discord_id": ctx.message.author.id}}) - self.db.update_one({"description": "rent"},{"$set":{"rent_time": time()/3600}}) + if not self.db.find_one(({"description": "rent"}) or self.id == 0: + self.db.update_one({"description": "rent"}, upsert=True, {"$set":{"discord_id": ctx.message.author.id}}) + self.db.update_one({"description": "rent"}, upsert=True, {"$set":{"rent_time": time()/3600}}) response = await ctx.send(f'A Beaglebone foi alugada com sucesso por `{ctx.author.mention}`, por duas horas a Beaglebone Black estará sobre sua posse') else: response = await ctx.send(f'A Beaglebone já foi alugada por <@`{self.id}`>, entre em contato com ela/ele ou aguarde o tempo de devolução') From 42800dd21a1791499ba14712905399e649612074 Mon Sep 17 00:00:00 2001 From: nosf Date: Mon, 5 Jul 2021 10:35:51 -0300 Subject: [PATCH 12/17] small debugs and database allocation changes --- cogs/Rent.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cogs/Rent.py b/cogs/Rent.py index c9661d9..da5481c 100644 --- a/cogs/Rent.py +++ b/cogs/Rent.py @@ -29,9 +29,9 @@ async def alugar(self, ctx): await reactToMessage(self.bot, ctx.message, [MESSAGE_EMOJI]) - if not self.db.find_one(({"description": "rent"}) or self.id == 0: - self.db.update_one({"description": "rent"}, upsert=True, {"$set":{"discord_id": ctx.message.author.id}}) - self.db.update_one({"description": "rent"}, upsert=True, {"$set":{"rent_time": time()/3600}}) + if not self.db.find_one({"description": "rent"}) or self.id == 0: + self.db.update_one({"description": "rent"}, {"$set":{"discord_id": ctx.message.author.id}}, upsert=True) + self.db.update_one({"description": "rent"}, {"$set":{"rent_time": time()/3600}}, upsert = True) response = await ctx.send(f'A Beaglebone foi alugada com sucesso por `{ctx.author.mention}`, por duas horas a Beaglebone Black estará sobre sua posse') else: response = await ctx.send(f'A Beaglebone já foi alugada por <@`{self.id}`>, entre em contato com ela/ele ou aguarde o tempo de devolução') @@ -63,7 +63,7 @@ async def devolver(self, ctx): @tasks.loop(minutes = 10) async def time_expired(self): if time()/3600 - self.time >= 2: - if self.id != 0 + if self.id != 0: txt = (f'O tempo de uso da beaglebone expirou <@`{self.id}`>. Alugue-a novamente caso não existam solicitações de aluguel anteriores.') channel = await self.bot.fetch_channel(CHANNEL_ID) await channel.send(content=txt) From aef82e91112bac64ec7fef8532a24f58372a2aff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ADra=20Canal?= <61601791+mairacanal@users.noreply.github.com> Date: Mon, 5 Jul 2021 12:15:11 -0300 Subject: [PATCH 13/17] Updating the database field --- cogs/Rent.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cogs/Rent.py b/cogs/Rent.py index da5481c..8a1fa7f 100644 --- a/cogs/Rent.py +++ b/cogs/Rent.py @@ -13,8 +13,8 @@ def __init__(self, bot): client = pymongo.MongoClient(MONGODB_ATLAS_URI) self.db = client['discord-bot']['discord-bot'] - self.id = self.db.find_one({"description": "rent"})['discord_id'] - self.time = self.db.find_one({"description": "rent"})['rent_time'] + self.id = self.db.find_one({"description": "rent"})['rent']['discord_id'] + self.time = self.db.find_one({"description": "rent"})['rent']['rent_time'] #A function to register the rent of a beaglebone black for 2 hours @commands.command( From 1fa57a8a5c58422ddda76e71d622d19b0133e754 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ADra=20Canal?= <61601791+mairacanal@users.noreply.github.com> Date: Mon, 5 Jul 2021 12:17:06 -0300 Subject: [PATCH 14/17] Removing unecessary alias --- cogs/Rent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cogs/Rent.py b/cogs/Rent.py index 8a1fa7f..b61d36e 100644 --- a/cogs/Rent.py +++ b/cogs/Rent.py @@ -20,7 +20,7 @@ def __init__(self, bot): @commands.command( brief='Uma função para alugar a Beaglebone Black de Maíra Canal (gerente do Alto Nível)', help='Use o comando >alugar para ter acesso irrestrito durante duas horas a uma Beaglebone Black. Caso alguém já esteja de posse dela, você será avisado/avisada', - aliases=['aluguel','aluga','alugar'] + aliases=['aluguel','aluga'] ) async def alugar(self, ctx): await ctx.trigger_typing() From 30a995c2fe22cbd09436ac4b8cd7c5488ee07f06 Mon Sep 17 00:00:00 2001 From: nosf Date: Mon, 5 Jul 2021 12:40:35 -0300 Subject: [PATCH 15/17] changing the non-commands to non-command calls such as self.id --- cogs/Rent.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cogs/Rent.py b/cogs/Rent.py index da5481c..b118473 100644 --- a/cogs/Rent.py +++ b/cogs/Rent.py @@ -30,11 +30,11 @@ async def alugar(self, ctx): await reactToMessage(self.bot, ctx.message, [MESSAGE_EMOJI]) if not self.db.find_one({"description": "rent"}) or self.id == 0: - self.db.update_one({"description": "rent"}, {"$set":{"discord_id": ctx.message.author.id}}, upsert=True) - self.db.update_one({"description": "rent"}, {"$set":{"rent_time": time()/3600}}, upsert = True) - response = await ctx.send(f'A Beaglebone foi alugada com sucesso por `{ctx.author.mention}`, por duas horas a Beaglebone Black estará sobre sua posse') + self.db.update_one({"description": "rent"}, {"$set":{"discord_id": ctx.message.author.id}}) + self.db.update_one({"description": "rent"}, {"$set":{"rent_time": time()/3600}}) + response = await ctx.send(f'A Beaglebone foi alugada com sucesso por {ctx.author.mention}, por duas horas a Beaglebone Black estará sobre sua posse') else: - response = await ctx.send(f'A Beaglebone já foi alugada por <@`{self.id}`>, entre em contato com ela/ele ou aguarde o tempo de devolução') + response = await ctx.send(f'A Beaglebone já foi alugada por <@{self.id}>, entre em contato com ela/ele ou aguarde o tempo de devolução') await reactToResponse(self.bot, response, [MESSAGE_EMOJI]) @@ -55,7 +55,7 @@ async def devolver(self, ctx): response = await ctx.send(f'Você não está de posse da Beaglebone. Alugue usando `>alugar` caso ela esteja livre.') else: self.db.update_one({"description": "rent"}, {"$set":{"discord_id": 0}}) - response = await ctx.send(f'A Beaglebone foi devolvida. Obrigado `{ctx.author.mention}`!') + response = await ctx.send(f'A Beaglebone foi devolvida. Obrigado {ctx.author.mention}!') await reactToResponse(self.bot, response, [MESSAGE_EMOJI]) @@ -64,7 +64,7 @@ async def devolver(self, ctx): async def time_expired(self): if time()/3600 - self.time >= 2: if self.id != 0: - txt = (f'O tempo de uso da beaglebone expirou <@`{self.id}`>. Alugue-a novamente caso não existam solicitações de aluguel anteriores.') + txt = (f'O tempo de uso da beaglebone expirou <@{self.id}>. Alugue-a novamente caso não existam solicitações de aluguel anteriores.') channel = await self.bot.fetch_channel(CHANNEL_ID) await channel.send(content=txt) self.db.update({"description": "rent"}, {"$set":{"discord_id": 0}}) From 3537667e006d2d80ad8cbad68f1515742c589b8c Mon Sep 17 00:00:00 2001 From: nosf Date: Mon, 5 Jul 2021 12:53:04 -0300 Subject: [PATCH 16/17] changing the non-commands to non-command calls such as self.id --- cogs/Rent.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cogs/Rent.py b/cogs/Rent.py index a9ab742..4e0b6be 100644 --- a/cogs/Rent.py +++ b/cogs/Rent.py @@ -13,8 +13,8 @@ def __init__(self, bot): client = pymongo.MongoClient(MONGODB_ATLAS_URI) self.db = client['discord-bot']['discord-bot'] - self.id = self.db.find_one({"description": "rent"})['rent']['discord_id'] - self.time = self.db.find_one({"description": "rent"})['rent']['rent_time'] + self.id = self.db.find_one({"description": "rent"})['discord_id'] + self.time = self.db.find_one({"description": "rent"})['rent_time'] #A function to register the rent of a beaglebone black for 2 hours @commands.command( From 8825d6d965056a4ac38a12c6083ec81d7c9fa0ee Mon Sep 17 00:00:00 2001 From: nosf Date: Mon, 5 Jul 2021 12:54:25 -0300 Subject: [PATCH 17/17] changing the non-commands to non-command calls such as self.id --- cogs/Rent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cogs/Rent.py b/cogs/Rent.py index 4e0b6be..b118473 100644 --- a/cogs/Rent.py +++ b/cogs/Rent.py @@ -20,7 +20,7 @@ def __init__(self, bot): @commands.command( brief='Uma função para alugar a Beaglebone Black de Maíra Canal (gerente do Alto Nível)', help='Use o comando >alugar para ter acesso irrestrito durante duas horas a uma Beaglebone Black. Caso alguém já esteja de posse dela, você será avisado/avisada', - aliases=['aluguel','aluga'] + aliases=['aluguel','aluga','alugar'] ) async def alugar(self, ctx): await ctx.trigger_typing()