diff --git a/.gitignore b/.gitignore index 6671836..002b075 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ __pycache__ -examples .env -errors -.cache \ No newline at end of file +.cache +Admin.py \ No newline at end of file diff --git a/config/config.py b/config/config.py index f4e1f9a..ceb1851 100644 --- a/config/config.py +++ b/config/config.py @@ -1,19 +1,15 @@ -from dotenv import dotenv_values +from decouple import config -CETUS_API = dotenv_values('.env')['CETUS_API'] -CAMBION_API = dotenv_values('.env')['CAMBION_API'] -FISSURES_API = dotenv_values('.env')['FISSURES_API'] -BOT_TOKEN = dotenv_values('.env')['BOT_TOKEN'] -SPOTIFY_ID = dotenv_values('.env')['SPOTIFY_ID'] -SPOTIFY_SECRET = dotenv_values('.env')['SPOTIFY_SECRET'] -SECRET_MESSAGE = dotenv_values('.env')['SECRET_MESSAGE'] -PHRASES_API = dotenv_values('.env')['PHRASES_API'] +CETUS_API = config('CETUS_API') +CAMBION_API = config('CAMBION_API') +FISSURES_API = config('FISSURES_API') +BOT_TOKEN = config('BOT_TOKEN') +SPOTIFY_ID = config('SPOTIFY_ID') +SPOTIFY_SECRET = config('SPOTIFY_SECRET') +SECRET_MESSAGE = config('SECRET_MESSAGE') +PHRASES_API = config('PHRASES_API') BOT_PREFIX = '!' -INITIAL_EXTENSIONS = {'vulkanbot.commands.Phrases', 'vulkanbot.commands.Warframe', - 'vulkanbot.general.Filter', 'vulkanbot.general.Control', 'vulkanbot.music.Music', - 'vulkanbot.commands.Random', 'vulkanbot.general.Admin'} - STARTUP_MESSAGE = 'Starting Vulkan...' STARTUP_COMPLETE_MESSAGE = 'Vulkan is now operating.' @@ -27,12 +23,9 @@ MAX_API_CAMBION_TRIES = 10 MAX_API_FISSURES_TRIES = 10 MAX_PRELOAD_SONGS = 10 -TRASH_CHANNEL_ID = 919961802140450837 - SONGINFO_UPLOADER = "Uploader: " SONGINFO_DURATION = "Duration: " - HELP_SKIP = 'Skip the current playing song' HELP_RESUME = 'Resumes the song player' HELP_CLEAR = 'Clear the queue' @@ -59,24 +52,9 @@ INVALID_INPUT = 'This type of input was too strange, try something better' DOWNLOADING_ERROR = 'An error occurred while downloading' SONG_ADDED = 'Song added to the Queue' -ABSOLUTE_PATH = '' -COOKIE_PATH = '/config/cookies/cookies.txt' - - COLOURS = { 'red': 0xDC143C, 'green': 0x58D68D, 'grey': 0x708090, 'blue': 0x3498DB } - -MEMBERS_MAXIMUM_DROPS = { - 'RafaelV': 1, - 'Gassu': 2, - 'LopesZ3R4': 4, - 'BABIGIRL': 4, - 'Hijãomi': 2, - 'Jillian': 4, - 'Maxymuns': 2 - -} diff --git a/main.py b/main.py index 124ed15..7a3a98f 100644 --- a/main.py +++ b/main.py @@ -1,10 +1,9 @@ -import os import discord +import os from config import config from discord.ext import commands - intents = discord.Intents.default() intents.members = True @@ -12,19 +11,12 @@ bot = commands.Bot(command_prefix=config.BOT_PREFIX, pm_help=True, case_insensitive=True, intents=intents) bot.remove_command('help') +if config.BOT_TOKEN == "": + exit() -if __name__ == '__main__': - config.ABSOLUTE_PATH = os.path.dirname(os.path.abspath(__file__)) - config.COOKIE_PATH = config.ABSOLUTE_PATH + config.COOKIE_PATH +for filename in os.listdir('./vulkan/commands'): + if filename.endswith('.py'): + bot.load_extension(f'vulkan.commands.{filename[:-3]}') - if config.BOT_TOKEN == "": - print("Error: No bot token!") - exit() - for extension in config.INITIAL_EXTENSIONS: - try: - bot.load_extension(extension) - except Exception as e: - print(e) - - bot.run(config.BOT_TOKEN, bot=True, reconnect=True) +bot.run(config.BOT_TOKEN, bot=True, reconnect=True) diff --git a/vulkanbot/general/Control.py b/vulkan/commands/Control.py similarity index 100% rename from vulkanbot/general/Control.py rename to vulkan/commands/Control.py diff --git a/vulkanbot/music/Music.py b/vulkan/commands/Music.py similarity index 98% rename from vulkanbot/music/Music.py rename to vulkan/commands/Music.py index 931d86e..9a89a25 100644 --- a/vulkanbot/music/Music.py +++ b/vulkan/commands/Music.py @@ -2,8 +2,8 @@ import discord from discord.ext import commands from config import config -from vulkanbot.music.Player import Player -from vulkanbot.music.utils import * +from vulkan.music.Player import Player +from vulkan.music.utils import * class Music(commands.Cog): diff --git a/vulkanbot/commands/Phrases.py b/vulkan/commands/Phrases.py similarity index 100% rename from vulkanbot/commands/Phrases.py rename to vulkan/commands/Phrases.py diff --git a/vulkanbot/commands/Random.py b/vulkan/commands/Random.py similarity index 100% rename from vulkanbot/commands/Random.py rename to vulkan/commands/Random.py diff --git a/vulkanbot/commands/Warframe.py b/vulkan/commands/Warframe.py similarity index 100% rename from vulkanbot/commands/Warframe.py rename to vulkan/commands/Warframe.py diff --git a/vulkanbot/music/Downloader.py b/vulkan/music/Downloader.py similarity index 98% rename from vulkanbot/music/Downloader.py rename to vulkan/music/Downloader.py index fa02f0a..1510e11 100644 --- a/vulkanbot/music/Downloader.py +++ b/vulkan/music/Downloader.py @@ -5,8 +5,8 @@ from config import config from yt_dlp import YoutubeDL from yt_dlp.utils import ExtractorError, DownloadError -from vulkanbot.music.Song import Song -from vulkanbot.music.utils import is_url +from vulkan.music.Song import Song +from vulkan.music.utils import is_url class Downloader(): diff --git a/vulkanbot/music/Interfaces.py b/vulkan/music/Interfaces.py similarity index 100% rename from vulkanbot/music/Interfaces.py rename to vulkan/music/Interfaces.py diff --git a/vulkanbot/music/Player.py b/vulkan/music/Player.py similarity index 97% rename from vulkanbot/music/Player.py rename to vulkan/music/Player.py index 11fb6ee..69f127e 100644 --- a/vulkanbot/music/Player.py +++ b/vulkan/music/Player.py @@ -3,11 +3,11 @@ from discord.ext import commands from config import config import datetime -from vulkanbot.music.Downloader import Downloader -from vulkanbot.music.Playlist import Playlist -from vulkanbot.music.Searcher import Searcher -from vulkanbot.music.Types import Provider -from vulkanbot.music.utils import * +from vulkan.music.Downloader import Downloader +from vulkan.music.Playlist import Playlist +from vulkan.music.Searcher import Searcher +from vulkan.music.Types import Provider +from vulkan.music.utils import * class Player(commands.Cog): diff --git a/vulkanbot/music/Playlist.py b/vulkan/music/Playlist.py similarity index 98% rename from vulkanbot/music/Playlist.py rename to vulkan/music/Playlist.py index 93babe7..66684e3 100644 --- a/vulkanbot/music/Playlist.py +++ b/vulkan/music/Playlist.py @@ -2,8 +2,8 @@ from collections import deque from config import config import random -from vulkanbot.music.Interfaces import IPlaylist -from vulkanbot.music.Song import Song +from vulkan.music.Interfaces import IPlaylist +from vulkan.music.Song import Song class Playlist(IPlaylist): diff --git a/vulkanbot/music/Searcher.py b/vulkan/music/Searcher.py similarity index 91% rename from vulkanbot/music/Searcher.py rename to vulkan/music/Searcher.py index b39aa42..648a105 100644 --- a/vulkanbot/music/Searcher.py +++ b/vulkan/music/Searcher.py @@ -1,6 +1,6 @@ -from vulkanbot.music.Types import Provider -from vulkanbot.music.Spotify import SpotifySearch -from vulkanbot.music.utils import is_url +from vulkan.music.Types import Provider +from vulkan.music.Spotify import SpotifySearch +from vulkan.music.utils import is_url class Searcher(): diff --git a/vulkanbot/music/Song.py b/vulkan/music/Song.py similarity index 97% rename from vulkanbot/music/Song.py rename to vulkan/music/Song.py index 3729c83..3c9a8cb 100644 --- a/vulkanbot/music/Song.py +++ b/vulkan/music/Song.py @@ -1,4 +1,4 @@ -from vulkanbot.music.Interfaces import ISong, IPlaylist +from vulkan.music.Interfaces import ISong, IPlaylist class Song(ISong): diff --git a/vulkanbot/music/Spotify.py b/vulkan/music/Spotify.py similarity index 100% rename from vulkanbot/music/Spotify.py rename to vulkan/music/Spotify.py diff --git a/vulkanbot/music/Types.py b/vulkan/music/Types.py similarity index 100% rename from vulkanbot/music/Types.py rename to vulkan/music/Types.py diff --git a/vulkanbot/music/utils.py b/vulkan/music/utils.py similarity index 100% rename from vulkanbot/music/utils.py rename to vulkan/music/utils.py diff --git a/vulkanbot/ErrorHandler.py b/vulkanbot/ErrorHandler.py deleted file mode 100644 index 5badfcc..0000000 --- a/vulkanbot/ErrorHandler.py +++ /dev/null @@ -1,73 +0,0 @@ -import sys -import datetime -import traceback - -MAXIMUM_TRIES = 10 - - -class ErrorHandler(): - """Receive errors to write into a log file - - Arg: - folder_path = Relative path from root to where the logs should be create - """ - - def __init__(self, folder_path='') -> None: - self.__folder_path = folder_path - - def write(self, error) -> bool: - """Write the error to a log file""" - if not isinstance(error, Exception): - return False - - full_path = self.__open_file() - if isinstance(full_path, bool): - return False - - error_str = self.__prepare_error(error) - - try: - with open(file=full_path, mode='w+') as log_file: - log_file.write(error_str) - return True - except Exception as e: - print(e) - return False - - def __prepare_error(self, error: Exception) -> str: - """Receive the error and return a good str""" - time_now = datetime.datetime.now() - tipo = sys.exc_info()[0] - msg = sys.exc_info()[1] - tb = traceback.format_tb(sys.exc_info()[2]) - error_str = f'Error Time: {time_now}\nTipo: {tipo}\nMsg: {msg}\nTraceback: {tb}' - return error_str - - def __open_file(self) -> str: - """Open a file to write the error""" - successfull = False - tries = 0 - - while True: - now = datetime.datetime.now() - date_now = now.strftime(r'%d.%b.%Y-%Hh%Mm%Ss') - - full_path = f'{self.__folder_path}/{date_now}({tries}).txt' - - try: - log_file = open(file=full_path, mode='w+') - log_file.close() - except Exception as e: - print(e) - tries += 1 - if tries > MAXIMUM_TRIES: - successfull = False - break - else: - successfull = True - break - - if successfull: - return full_path - else: - return False diff --git a/vulkanbot/commands/__init__.py b/vulkanbot/commands/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/vulkanbot/general/Admin.py b/vulkanbot/general/Admin.py deleted file mode 100644 index a474292..0000000 --- a/vulkanbot/general/Admin.py +++ /dev/null @@ -1,51 +0,0 @@ -from discord.ext import commands -from discord import Member, Client -from config import config - - -class Admin(commands.Cog): - """Deal with administration of users in server""" - - def __init__(self, bot: Client): - self.__bot = bot - - @commands.command(name='drop', help='Manda um membro para a Terapia') - async def drop(self, ctx, name): - user: Member = None - guild = ctx.guild - - for member in guild.members: - if member.name == name: - user = member - break - - if user == None: - await ctx.send(f'{name} não foi encontrado, utilize o nome de usuário ao invés do apelido do servidor') - return - - permanent_drops = False - maximum_drops = None - - try: - maximum_drops = config.MEMBERS_MAXIMUM_DROPS[user.name] - except KeyError: - permanent_drops = True - except Exception as e: - await ctx.send('Houve algum erro :/') - return - - if maximum_drops == 0: - await ctx.send(f'{user.name} já foi dropado várias vezes, larga o cara bicho') - return - - if user.voice == None: - await ctx.send(f'{user.name} precisa estar conectado a um canal de voz antes') - else: - await user.move_to(None) # Remove from voice - if not permanent_drops: - # Att the life of user - config.MEMBERS_MAXIMUM_DROPS[user.name] -= 1 - - -def setup(bot): - bot.add_cog(Admin(bot)) diff --git a/vulkanbot/general/Filter.py b/vulkanbot/general/Filter.py deleted file mode 100644 index cfb3ae2..0000000 --- a/vulkanbot/general/Filter.py +++ /dev/null @@ -1,21 +0,0 @@ -from discord import Client -from discord.ext import commands - - -class Filter(commands.Cog): - """Deal with filtering of discord messages""" - - def __init__(self, bot: Client): - self.__bot = bot - - @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/vulkanbot/general/__init__.py b/vulkanbot/general/__init__.py deleted file mode 100644 index e69de29..0000000