Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions cogs/Counters.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand All @@ -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))
Expand Down
74 changes: 74 additions & 0 deletions cogs/Rent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import pymongo
from discord.ext import tasks, commands
from util import *
from config import MONGODB_ATLAS_URI
from config import CHANNEL_ID

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)
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']

#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','alugar']
)
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"}) or 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.id}>, 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']
)
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.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_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])


@tasks.loop(minutes = 10)
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.')
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))

4 changes: 2 additions & 2 deletions util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
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
MESSAGE_EMOJI = '🐴' # emoji that'll be mainly used to react to user messages
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
'🤠', '🍉', '💘', '🏂',
Expand Down