Uploading JuicyBot Base v0.0.1

This commit is contained in:
juicy 2020-05-05 13:06:53 +02:00
parent 67ebd2071f
commit edd8fcc9ad
25 changed files with 270 additions and 0 deletions

3
.idea/.gitignore vendored Normal file

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

@ -0,0 +1,19 @@
<component name="ProjectDictionaryState">
<dictionary name="cekey">
<words>
<w>cooldown</w>
<w>couldn</w>
<w>dataframe</w>
<w>emoji</w>
<w>gamertag</w>
<w>platformid</w>
<w>playerdata</w>
<w>playerid</w>
<w>psyonix</w>
<w>qqfcwij</w>
<w>racker</w>
<w>rlstats</w>
<w>xbox</w>
</words>
</dictionary>
</component>

10
.idea/discordbotto.iml Normal file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.idea" />
</content>
<orderEntry type="jdk" jdkName="Python 3.7 (untitled)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

4
.idea/misc.xml Normal file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (untitled)" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml Normal file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/discordbotto.iml" filepath="$PROJECT_DIR$/.idea/discordbotto.iml" />
</modules>
</component>
</project>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

65
commands/admin.py Normal file

@ -0,0 +1,65 @@
from discord.ext import commands
from config import cogs
import configloader
class Admin(commands.Cog):
def __init__(self, bot):
self.bot = bot
async def cog_check(self, ctx):
return await ctx.bot.is_owner(ctx.author)
@commands.command(description='Shows existing Cogs',
usage=f'{configloader.__prefix__}cogs',
hidden=True)
@commands.cooldown(1, 2, commands.BucketType.user)
async def cogs(self, ctx):
await ctx.send(cogs.__cogs__)
@commands.command(name='load',
description='Loads a Module',
usage=f'{configloader.__prefix__}load <cog>',
hidden=True)
@commands.cooldown(1, 2, commands.BucketType.user)
async def load_cog(self, ctx, cog):
try:
self.bot.load_extension(f"commands.{cog}")
except Exception as err:
print(f"{cog} couldn't be loaded")
raise err
else:
await ctx.send(f'{cog} : Successfully loaded')
@commands.command(name='unload',
description='Unloads a Module',
usage=f'{configloader.__prefix__}unload <cog>',
hidden=True)
@commands.cooldown(1, 2, commands.BucketType.user)
async def unload_cog(self, ctx, cog):
try:
self.bot.unload_extension(f"commands.{cog}")
except Exception as err:
print(f"{cog} : couldn't be unloaded")
raise err
else:
await ctx.send(f'{cog} : Successfully unloaded')
@commands.command(name='reload',
description='Reloads a Module',
usage=f'{configloader.__prefix__}reload <cog>',
hidden=True)
@commands.cooldown(1, 2, commands.BucketType.user)
async def reload_cog(self, ctx, cog):
try:
self.bot.unload_extension(f"commands.{cog}")
self.bot.load_extension(f'commands.{cog}')
except Exception as err:
print(f"'{cog} : couldn't be reloaded")
raise err
else:
await ctx.send(f'{cog} : Successfully reloaded')
def setup(bot):
bot.add_cog(Admin(bot))

12
commands/help.py Normal file

@ -0,0 +1,12 @@
from discord.ext import commands
import configloader
class Help(commands.Cog):
def __init__(self, bot):
pass
def setup(bot):
bot.remove_command("help")
bot.add_cog(Help(bot))

Binary file not shown.

Binary file not shown.

5
config/cogs.py Normal file

@ -0,0 +1,5 @@
__cogs__ = [
'commands.admin',
'commands.help',
'handlers.errorHandling'
]

4
config/config.py Normal file

@ -0,0 +1,4 @@
__token__ = "YOUR TOKEN"
__prefix__ = "!"
__greet_channel__ = "YOUR GREET CHANNEL ID"
__api_key__ = ""

11
configloader.py Normal file

@ -0,0 +1,11 @@
from config.cogs import __cogs__
from utils import embed
try:
from config.config import __token__, __prefix__, __greet_channel__, __api_key__
except ImportError:
import os
__token__ = os.environ.get('DISCORD_TOKEN')
__prefix__ = os.environ.get('DISCORD_PREFIX')
__greet_channel__ = os.environ.get('DISCORD_GREET_CHANNEL')
__api_key__ = os.environ.get('DISCORD_API_KEY')

BIN
db/db.db Normal file

Binary file not shown.

Binary file not shown.

41
handlers/errorHandling.py Normal file

@ -0,0 +1,41 @@
import traceback
import sys
from discord.ext import commands
import discord
import configloader
class ErrorHandler(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.Cog.listener()
async def on_command_error(self, ctx, error):
bot_app_info = await self.bot.application_info()
ignore_error = (commands.CommandNotFound, commands.UserInputError)
if isinstance(error, ignore_error):
return
elif isinstance(error, commands.CommandOnCooldown):
embed = configloader.embed.messageEmbed(f"This command is ratelimited, please try again in",
"{:.2f}s".format(error.retry_after),
f"{bot_app_info.owner}", f"{bot_app_info.icon_url}")
return await ctx.send(embed=embed)
elif isinstance(error, commands.NoPrivateMessage):
try:
embed = configloader.embed.messageEmbed(f"This Command can't be used in Private Messages.",
"{:.2f}s".format(ctx.command),
f"{bot_app_info.owner}", f"{bot_app_info.icon_url}")
return await ctx.author.send(embed=embed)
except:
pass
elif isinstance(error, commands.MissingPermissions):
embed = configloader.embed.messageEmbed(f"You don't have Permissions to use this command",
"{:.2f}s".format(ctx.command),
f"{bot_app_info.owner}", f"{bot_app_info.icon_url}")
return await ctx.send(embed=embed)
def setup(bot):
bot.add_cog(ErrorHandler(bot))

60
index.py Normal file

@ -0,0 +1,60 @@
import discord
from discord.ext import commands
import sqlite3
import configloader
import random
import logging
from logging.handlers import RotatingFileHandler
logger = logging.getLogger('discord')
logger.setLevel(logging.WARNING)
handler = RotatingFileHandler(filename='logs/bot.log', maxBytes=1024 * 5, backupCount=2, encoding='utf-8', mode='w')
handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
logger.addHandler(handler)
__version__ = '0.0.1'
bot = commands.Bot(command_prefix=configloader.__prefix__)
def Database(db):
with sqlite3.connect(db) as con:
c = con.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS `users` (`name`,`id`, `platform`);''')
con.commit()
c.close()
@bot.event
async def on_ready():
bot_app_info = await bot.application_info()
print("------------------------------------")
print(f"Owner: {bot_app_info.owner}")
print(f"Bot-Name: {bot.user.name}")
print(f"Bot-ID: {bot.user.id}")
print(f"Bot Version: {__version__}")
print("------------------------------------")
for cog in configloader.__cogs__:
try:
bot.load_extension(cog)
print(f"{cog} loaded")
except Exception as err:
print(f"Couldn't load cog: {cog}")
raise err
Database("db/db.db")
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="Juicy developing."))
@bot.event
async def on_member_join(member):
bot_app_info = await bot.application_info()
emoji = [':wink:', ':wave:', ':tada:']
channel = bot.get_channel(int(configloader.__greet_channel__))
guild = member.guild
embed = configloader.embed.messageEmbed(f"Willkommen bei {guild.name} {random.choice(emoji)}",
f"{member.mention}",
f"{bot_app_info.owner}", f"{bot_app_info.icon_url}")
await channel.send(embed=embed)
if __name__ == "__main__":
bot.run(configloader.__token__)

10
logs/bot.log Normal file

@ -0,0 +1,10 @@
2020-05-05 11:41:55,808:WARNING:discord.client: PyNaCl is not installed, voice will NOT be supported
2020-05-05 11:42:44,589:WARNING:discord.client: PyNaCl is not installed, voice will NOT be supported
2020-05-05 12:02:46,688:WARNING:discord.client: PyNaCl is not installed, voice will NOT be supported
2020-05-05 12:05:01,635:WARNING:discord.client: PyNaCl is not installed, voice will NOT be supported
2020-05-05 12:08:16,694:WARNING:discord.client: PyNaCl is not installed, voice will NOT be supported
2020-05-05 12:10:00,026:WARNING:discord.client: PyNaCl is not installed, voice will NOT be supported
2020-05-05 12:11:03,303:WARNING:discord.client: PyNaCl is not installed, voice will NOT be supported
2020-05-05 12:13:57,539:WARNING:discord.client: PyNaCl is not installed, voice will NOT be supported
2020-05-05 12:14:11,853:WARNING:discord.client: PyNaCl is not installed, voice will NOT be supported
2020-05-05 12:21:59,614:WARNING:discord.client: PyNaCl is not installed, voice will NOT be supported

3
requirements.txt Normal file

@ -0,0 +1,3 @@
discord.py
pandas
requests

Binary file not shown.

9
utils/embed.py Normal file

@ -0,0 +1,9 @@
import discord
from datetime import date
def messageEmbed(title, text, owner, icon):
embed = discord.Embed(color=0xffd540)
embed.add_field(name=f"{title}", value=f"{text}")
embed.set_footer(text=f"© {owner}{date.today()}", icon_url=f"{icon}")
return embed