This commit is contained in:
2024-06-05 19:05:10 +02:00
commit 2ad8b5ad4f
9 changed files with 147 additions and 0 deletions

6
.env.example Normal file
View File

@@ -0,0 +1,6 @@
discord_bot_token=
mysql_host=
mysql_user=
mysql_databse=
mysql_password=
bot_version=1.0

Binary file not shown.

58
cogs/template.py Normal file
View File

@@ -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))

Binary file not shown.

Binary file not shown.

6
libs/lib_checks.py Normal file
View File

@@ -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

44
libs/lib_mysql.py Normal file
View File

@@ -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()

25
main.py Normal file
View File

@@ -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"))

8
requirements.txt Normal file
View File

@@ -0,0 +1,8 @@
py-cord
instagrapi
mysql-connector-python
requests
python-dotenv
pillow
pytz
pyyaml