commit 2ad8b5ad4fde82d7c8de1001f1f5b86da1525cf4 Author: Jonathan Nebel Date: Wed Jun 5 19:05:10 2024 +0200 upload diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..4472777 --- /dev/null +++ b/.env.example @@ -0,0 +1,6 @@ +discord_bot_token= +mysql_host= +mysql_user= +mysql_databse= +mysql_password= +bot_version=1.0 diff --git a/cogs/__pycache__/template.cpython-39.pyc b/cogs/__pycache__/template.cpython-39.pyc new file mode 100644 index 0000000..562e2ec Binary files /dev/null and b/cogs/__pycache__/template.cpython-39.pyc differ diff --git a/cogs/template.py b/cogs/template.py new file mode 100644 index 0000000..cdd9dd6 --- /dev/null +++ b/cogs/template.py @@ -0,0 +1,58 @@ +from datetime import datetime, timedelta +import time +import random +import discord +from discord.ext import commands +from discord.commands import slash_command, Option +import sys +import os +from discord.utils import get + +sys.path.insert(0, '..') + +from libs import lib_mysql +from libs import lib_checks + + +class Help(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @slash_command(description="Schau dir den Hilfe Text an") + async def demo(self, ctx): + my_db = lib_mysql.MariaDB(os.getenv("mysql_host"), os.getenv("mysql_user"), os.getenv("mysql_databse"), os.getenv("mysql_password")) + my_db.connect() + + sql = "SELECT * FROM `members` WHERE member_id = %s" + val = (1,) + member = my_db.select(sql, val) + print(member) + sql = "INSERT INTO members (member_id, last_message) VALUES (%s, %s)" + val = (1, 0,) + my_db.insert(sql, val) + + embed = discord.Embed( + title=f"Hilfe Text", + description=f"Hier findest du ein übersicht aller Befehle", + color=discord.Color.from_rgb(108, 0, 0) + ) + thumbnail_list = os.getenv("level_systen_thumbnail_url").split(",") + thumbnail_id = random.randint(0, len(thumbnail_list) - 1) + embed.set_thumbnail(url=thumbnail_list[thumbnail_id]) + embed.add_field(name="/help", value="zeigt die Hilfe Texte an", inline=False) + embed.add_field(name="/info", value="Zeigt dir Details zu dir an", inline=False) + embed.add_field(name="/gamble", value="Gewinne alle 7 Tage einen zufälligen Gegenstand", inline=False) + embed.add_field(name="/inventar", value="Zeige dir den Inhalt deines Inventars an", inline=False) + embed.add_field(name="/sell", value="Verkaufe doppelte Gegenstände", inline=False) + embed.add_field(name="/create_birthday", value="Lege deinen Geburtstag an", inline=False) + embed.add_field(name="/loben", value="Lobe eine Person", inline=False) + embed.add_field(name="/Lost", value="Markiere ein Person als Lost, anchdem diese Lost war", inline=False) + embed.add_field(name="/klazmo", value="Zeige dir die Werbung für Klazmo an", inline=False) + embed.add_field(name="/mmoga", value="Zeige dir die Werbung für Mmoga an", inline=False) + bot_version = os.getenv("bot_version") + embed.set_footer(text=f"Version: {bot_version}") + await ctx.respond(embed=embed, ephemeral=True) + + +def setup(bot): + bot.add_cog(Help(bot)) diff --git a/libs/__pycache__/lib_checks.cpython-39.pyc b/libs/__pycache__/lib_checks.cpython-39.pyc new file mode 100644 index 0000000..3a8269a Binary files /dev/null and b/libs/__pycache__/lib_checks.cpython-39.pyc differ diff --git a/libs/__pycache__/lib_mysql.cpython-39.pyc b/libs/__pycache__/lib_mysql.cpython-39.pyc new file mode 100644 index 0000000..006e25b Binary files /dev/null and b/libs/__pycache__/lib_mysql.cpython-39.pyc differ diff --git a/libs/lib_checks.py b/libs/lib_checks.py new file mode 100644 index 0000000..b0fe15a --- /dev/null +++ b/libs/lib_checks.py @@ -0,0 +1,6 @@ +def has_role(user_roles, searched_role): + found = False + for i in user_roles: + if i.name == searched_role: + found = True + return found diff --git a/libs/lib_mysql.py b/libs/lib_mysql.py new file mode 100644 index 0000000..3adf719 --- /dev/null +++ b/libs/lib_mysql.py @@ -0,0 +1,44 @@ +import os +import mysql.connector + + +class MariaDB(): + username = None + password = None + site_url = None + + def __init__(self, mysql_host, mysql_user, mysql_databse, mysql_password): + self.mysql_host = mysql_host + self.mysql_user = mysql_user + self.mysql_password = mysql_password + self.mysql_databse = mysql_databse + + def connect(self): + mydb = mysql.connector.connect( + host=self.mysql_host, + user=self.mysql_user, + password=self.mysql_password, + database=self.mysql_databse + ) + self.mydb = mydb + self.mycursor = mydb.cursor(buffered=True, dictionary=True) + + def insert(self, sql, val): + self.mycursor.execute(sql, val) + self.mydb.commit() + + print(f"MySQL-Connection: {self.mycursor.rowcount} record inserted") + + def select(self, sql, val): + if len(val) == 0: + self.mycursor.execute(sql) + else: + self.mycursor.execute(sql, val) + + myresult = self.mycursor.fetchall() + return myresult + + + + def disconnect(self): + self.mydb.disconnect() \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..49f569d --- /dev/null +++ b/main.py @@ -0,0 +1,25 @@ +import discord +import os +from dotenv import load_dotenv + +load_dotenv() + +intents = discord.Intents.default() +intents.message_content = True +intents.members = True + +bot = discord.Bot(intents=intents) + + +@bot.event +async def on_ready(): + print(f"The Bot {bot.user} has been started successfully") + + +if __name__ == "__main__": + + for filename in os.listdir("cogs"): + if filename.endswith(".py"): + bot.load_extension(f"cogs.{filename[:-3]}") + + bot.run(os.getenv("discord_bot_token")) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..60cc165 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,8 @@ +py-cord +instagrapi +mysql-connector-python +requests +python-dotenv +pillow +pytz +pyyaml \ No newline at end of file