mirror of
https://github.com/RafaelSolVargas/Vulkan.git
synced 2025-10-29 16:57:23 +00:00
Renaming modules, removing useless and changing logic of bot initialization
This commit is contained in:
parent
9c327b8dbf
commit
74d91c15f8
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,5 +1,4 @@
|
|||||||
__pycache__
|
__pycache__
|
||||||
examples
|
|
||||||
.env
|
.env
|
||||||
errors
|
|
||||||
.cache
|
.cache
|
||||||
|
Admin.py
|
||||||
@ -1,19 +1,15 @@
|
|||||||
from dotenv import dotenv_values
|
from decouple import config
|
||||||
|
|
||||||
CETUS_API = dotenv_values('.env')['CETUS_API']
|
CETUS_API = config('CETUS_API')
|
||||||
CAMBION_API = dotenv_values('.env')['CAMBION_API']
|
CAMBION_API = config('CAMBION_API')
|
||||||
FISSURES_API = dotenv_values('.env')['FISSURES_API']
|
FISSURES_API = config('FISSURES_API')
|
||||||
BOT_TOKEN = dotenv_values('.env')['BOT_TOKEN']
|
BOT_TOKEN = config('BOT_TOKEN')
|
||||||
SPOTIFY_ID = dotenv_values('.env')['SPOTIFY_ID']
|
SPOTIFY_ID = config('SPOTIFY_ID')
|
||||||
SPOTIFY_SECRET = dotenv_values('.env')['SPOTIFY_SECRET']
|
SPOTIFY_SECRET = config('SPOTIFY_SECRET')
|
||||||
SECRET_MESSAGE = dotenv_values('.env')['SECRET_MESSAGE']
|
SECRET_MESSAGE = config('SECRET_MESSAGE')
|
||||||
PHRASES_API = dotenv_values('.env')['PHRASES_API']
|
PHRASES_API = config('PHRASES_API')
|
||||||
|
|
||||||
BOT_PREFIX = '!'
|
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_MESSAGE = 'Starting Vulkan...'
|
||||||
STARTUP_COMPLETE_MESSAGE = 'Vulkan is now operating.'
|
STARTUP_COMPLETE_MESSAGE = 'Vulkan is now operating.'
|
||||||
@ -27,12 +23,9 @@ MAX_API_CAMBION_TRIES = 10
|
|||||||
MAX_API_FISSURES_TRIES = 10
|
MAX_API_FISSURES_TRIES = 10
|
||||||
MAX_PRELOAD_SONGS = 10
|
MAX_PRELOAD_SONGS = 10
|
||||||
|
|
||||||
TRASH_CHANNEL_ID = 919961802140450837
|
|
||||||
|
|
||||||
SONGINFO_UPLOADER = "Uploader: "
|
SONGINFO_UPLOADER = "Uploader: "
|
||||||
SONGINFO_DURATION = "Duration: "
|
SONGINFO_DURATION = "Duration: "
|
||||||
|
|
||||||
|
|
||||||
HELP_SKIP = 'Skip the current playing song'
|
HELP_SKIP = 'Skip the current playing song'
|
||||||
HELP_RESUME = 'Resumes the song player'
|
HELP_RESUME = 'Resumes the song player'
|
||||||
HELP_CLEAR = 'Clear the queue'
|
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'
|
DOWNLOADING_ERROR = 'An error occurred while downloading'
|
||||||
SONG_ADDED = 'Song added to the Queue'
|
SONG_ADDED = 'Song added to the Queue'
|
||||||
|
|
||||||
ABSOLUTE_PATH = ''
|
|
||||||
COOKIE_PATH = '/config/cookies/cookies.txt'
|
|
||||||
|
|
||||||
|
|
||||||
COLOURS = {
|
COLOURS = {
|
||||||
'red': 0xDC143C,
|
'red': 0xDC143C,
|
||||||
'green': 0x58D68D,
|
'green': 0x58D68D,
|
||||||
'grey': 0x708090,
|
'grey': 0x708090,
|
||||||
'blue': 0x3498DB
|
'blue': 0x3498DB
|
||||||
}
|
}
|
||||||
|
|
||||||
MEMBERS_MAXIMUM_DROPS = {
|
|
||||||
'RafaelV': 1,
|
|
||||||
'Gassu': 2,
|
|
||||||
'LopesZ3R4': 4,
|
|
||||||
'BABIGIRL': 4,
|
|
||||||
'Hijãomi': 2,
|
|
||||||
'Jillian': 4,
|
|
||||||
'Maxymuns': 2
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
22
main.py
22
main.py
@ -1,10 +1,9 @@
|
|||||||
import os
|
|
||||||
import discord
|
import discord
|
||||||
|
import os
|
||||||
|
|
||||||
from config import config
|
from config import config
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
|
||||||
|
|
||||||
intents = discord.Intents.default()
|
intents = discord.Intents.default()
|
||||||
intents.members = True
|
intents.members = True
|
||||||
|
|
||||||
@ -12,19 +11,12 @@ bot = commands.Bot(command_prefix=config.BOT_PREFIX, pm_help=True,
|
|||||||
case_insensitive=True, intents=intents)
|
case_insensitive=True, intents=intents)
|
||||||
bot.remove_command('help')
|
bot.remove_command('help')
|
||||||
|
|
||||||
|
if config.BOT_TOKEN == "":
|
||||||
|
exit()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
for filename in os.listdir('./vulkan/commands'):
|
||||||
config.ABSOLUTE_PATH = os.path.dirname(os.path.abspath(__file__))
|
if filename.endswith('.py'):
|
||||||
config.COOKIE_PATH = config.ABSOLUTE_PATH + config.COOKIE_PATH
|
bot.load_extension(f'vulkan.commands.{filename[:-3]}')
|
||||||
|
|
||||||
if config.BOT_TOKEN == "":
|
|
||||||
print("Error: No bot token!")
|
|
||||||
exit()
|
|
||||||
|
|
||||||
for extension in config.INITIAL_EXTENSIONS:
|
bot.run(config.BOT_TOKEN, bot=True, reconnect=True)
|
||||||
try:
|
|
||||||
bot.load_extension(extension)
|
|
||||||
except Exception as e:
|
|
||||||
print(e)
|
|
||||||
|
|
||||||
bot.run(config.BOT_TOKEN, bot=True, reconnect=True)
|
|
||||||
|
|||||||
@ -2,8 +2,8 @@ import discord
|
|||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
|
||||||
from config import config
|
from config import config
|
||||||
from vulkanbot.music.Player import Player
|
from vulkan.music.Player import Player
|
||||||
from vulkanbot.music.utils import *
|
from vulkan.music.utils import *
|
||||||
|
|
||||||
|
|
||||||
class Music(commands.Cog):
|
class Music(commands.Cog):
|
||||||
@ -5,8 +5,8 @@ from config import config
|
|||||||
from yt_dlp import YoutubeDL
|
from yt_dlp import YoutubeDL
|
||||||
from yt_dlp.utils import ExtractorError, DownloadError
|
from yt_dlp.utils import ExtractorError, DownloadError
|
||||||
|
|
||||||
from vulkanbot.music.Song import Song
|
from vulkan.music.Song import Song
|
||||||
from vulkanbot.music.utils import is_url
|
from vulkan.music.utils import is_url
|
||||||
|
|
||||||
|
|
||||||
class Downloader():
|
class Downloader():
|
||||||
@ -3,11 +3,11 @@ from discord.ext import commands
|
|||||||
from config import config
|
from config import config
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from vulkanbot.music.Downloader import Downloader
|
from vulkan.music.Downloader import Downloader
|
||||||
from vulkanbot.music.Playlist import Playlist
|
from vulkan.music.Playlist import Playlist
|
||||||
from vulkanbot.music.Searcher import Searcher
|
from vulkan.music.Searcher import Searcher
|
||||||
from vulkanbot.music.Types import Provider
|
from vulkan.music.Types import Provider
|
||||||
from vulkanbot.music.utils import *
|
from vulkan.music.utils import *
|
||||||
|
|
||||||
|
|
||||||
class Player(commands.Cog):
|
class Player(commands.Cog):
|
||||||
@ -2,8 +2,8 @@ from collections import deque
|
|||||||
from config import config
|
from config import config
|
||||||
import random
|
import random
|
||||||
|
|
||||||
from vulkanbot.music.Interfaces import IPlaylist
|
from vulkan.music.Interfaces import IPlaylist
|
||||||
from vulkanbot.music.Song import Song
|
from vulkan.music.Song import Song
|
||||||
|
|
||||||
|
|
||||||
class Playlist(IPlaylist):
|
class Playlist(IPlaylist):
|
||||||
@ -1,6 +1,6 @@
|
|||||||
from vulkanbot.music.Types import Provider
|
from vulkan.music.Types import Provider
|
||||||
from vulkanbot.music.Spotify import SpotifySearch
|
from vulkan.music.Spotify import SpotifySearch
|
||||||
from vulkanbot.music.utils import is_url
|
from vulkan.music.utils import is_url
|
||||||
|
|
||||||
|
|
||||||
class Searcher():
|
class Searcher():
|
||||||
@ -1,4 +1,4 @@
|
|||||||
from vulkanbot.music.Interfaces import ISong, IPlaylist
|
from vulkan.music.Interfaces import ISong, IPlaylist
|
||||||
|
|
||||||
|
|
||||||
class Song(ISong):
|
class Song(ISong):
|
||||||
@ -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
|
|
||||||
@ -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))
|
|
||||||
@ -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))
|
|
||||||
Loading…
x
Reference in New Issue
Block a user