commit 86255355c446deffe41240210a81b128bb637e61 Author: Rafael Vargas Date: Wed Dec 22 20:52:26 2021 -0400 Sending initial files of Vulkan BOT diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e0da185 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +__pycache__ +cogs/music* +.env \ No newline at end of file diff --git a/cogs/control.py b/cogs/control.py new file mode 100644 index 0000000..c612c4b --- /dev/null +++ b/cogs/control.py @@ -0,0 +1,34 @@ +from discord.ext.commands.errors import CommandNotFound, MissingRequiredArgument +from discord.ext import commands + + +class Control(commands.Cog): + """Control the flow of the Bot""" + + def __init__(self, bot): + self.__bot = bot + + @property + def bot(self): + return self.__bot + + @bot.setter + def bot(self, newBot): + self.__bot = newBot + + @commands.Cog.listener() + async def on_ready(self): + print(f'Bot {self.__bot.user.name} inicializado') + + @commands.Cog.listener() + async def on_command_error(self, ctx, error): + if isinstance(error, MissingRequiredArgument): + await ctx.channel.send(f'Falta argumentos. Digite {self.__bot.prefix}help para ver os comandos') + elif isinstance(error, CommandNotFound): + await ctx.channel.send(f'O comando não existe') + else: + raise error + + +def setup(bot): + bot.add_cog(Control(bot)) diff --git a/cogs/filter.py b/cogs/filter.py new file mode 100644 index 0000000..1e88b53 --- /dev/null +++ b/cogs/filter.py @@ -0,0 +1,28 @@ +from discord.ext import commands + + +class Filter(commands.Cog): + """Deal with filtering of discord messages""" + + def __init__(self, bot): + self.__bot = bot + + @property + def bot(self): + return self.__bot + + @bot.setter + def bot(self, newBot): + self.__bot = newBot + + @commands.Cog.listener() + async def on_message(self, message): + if message.author == self.__bot.user: + return + + if 'elx' in message.content: + await message.channel.send(f'Coé {message.author.name}, tu é gay memo hein bicho') + + +def setup(bot): + bot.add_cog(Filter(bot)) diff --git a/cogs/phrases.py b/cogs/phrases.py new file mode 100644 index 0000000..58d1642 --- /dev/null +++ b/cogs/phrases.py @@ -0,0 +1,48 @@ +import requests +import json +import discord +from discord.ext import commands + + +class Phrases(commands.Cog): + """Deal with the generation of motivational phrases""" + + def __init__(self, bot): + self.__bot = bot + + @property + def bot(self): + return self.__bot + + @bot.setter + def bot(self, newBot): + self.__bot = newBot + + @commands.command(name='frase', help='Envia uma frase legal no seu PV') + async def send_phrase(self, ctx): + while True: + try: + response = requests.get( + 'http://api.forismatic.com/api/1.0/?method=getQuote&key=457653&format=json&lang=en') + data = json.loads(response.content) + + phrase = data['quoteText'] + author = data['quoteAuthor'] + + text = f'{phrase} \nBy: {author}' + await ctx.author.send(text) + break + except json.decoder.JSONDecodeError: + continue + except discord.errors.Forbidden as e: + print(e) + await ctx.channel.send('Não posso te enviar a frase, habilite para receber mensagens de qualquer pessoa no servidor (Opções > Privacidade)') + break + except Exception as e: + print(e) + await ctx.channel.send('Houve um erro inesperado :/') + break + + +def setup(bot): + bot.add_cog(Phrases(bot)) diff --git a/cogs/talk.py b/cogs/talk.py new file mode 100644 index 0000000..2468478 --- /dev/null +++ b/cogs/talk.py @@ -0,0 +1,20 @@ +from discord.ext import commands + + +class Talks(commands.Cog): + """Deal with talks to users""" + + def __init__(self, bot): + self.__bot = bot + + @property + def bot(self): + return self.__bot + + @bot.setter + def bot(self, newBot): + self.__bot = newBot + + +def setup(bot): + bot.add_cog(Talks(bot)) diff --git a/cogs/warframe.py b/cogs/warframe.py new file mode 100644 index 0000000..17189ba --- /dev/null +++ b/cogs/warframe.py @@ -0,0 +1,51 @@ +import requests +import json +import discord +from dotenv import dotenv_values +from discord.ext import commands +CETUS_API = dotenv_values('.env')['CETUS_API'] + + +class Warframe(commands.Cog): + """Deal with the generation of warframe data""" + + def __init__(self, bot): + self.__bot = bot + + @property + def bot(self): + return self.__bot + + @bot.setter + def bot(self, newBot): + self.__bot = newBot + + @commands.command(name='cetus', help='Informa o tempo atual de Cetus - Warframe') + async def get_cetus(self, ctx): + try: + response = requests.get(CETUS_API) + data = json.loads(response.content) + short = data['shortString'] + + responseText = f'{short}' + + embed = discord.Embed( + title='Warframe Cetus Timing', + description=responseText, + colour=0xFF0000 + ) + await ctx.send(embed=embed) + + except Exception as e: + print(e) + responseText = f'Houve um erro inesperado :/' + embed = discord.Embed( + title='Warframe Cetus Timing', + description=responseText, + colour=0xFF0000 + ) + await ctx.send(embed=embed) + + +def setup(bot): + bot.add_cog(Warframe(bot)) diff --git a/main.py b/main.py new file mode 100644 index 0000000..0dbf4f2 --- /dev/null +++ b/main.py @@ -0,0 +1,23 @@ +import os +import discord +from dotenv import dotenv_values +from discord.ext import commands + +TOKEN_BOT = dotenv_values('.env')['TOKEN_BOT'] + +intents = discord.Intents.default() +intents.members = True + +client = commands.Bot(command_prefix="!", + case_insensitive=True, intents=intents) +client.remove_command('help') + + +def load_cogs(bot): + for filename in os.listdir('cogs'): + if filename.endswith('.py'): + bot.load_extension(f'cogs.{filename[:-3]}') + + +load_cogs(client) +client.run(TOKEN_BOT) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..821e985 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +discord.py +discord.py[voice] +youtube_dl +PyNaCl