From c69b817caf48ad31212468d17934fd4996c02256 Mon Sep 17 00:00:00 2001 From: DestinyofYeet Date: Tue, 16 Mar 2021 23:43:44 +0100 Subject: [PATCH 1/9] added cogs --- bot.py | 358 ++++++++----------------------------------- cogs/benutzerinfo.py | 36 +++++ cogs/corona.py | 52 +++++++ cogs/events.py | 52 +++++++ cogs/lol.py | 92 +++++++++++ cogs/mc.py | 104 +++++++++++++ cogs/wetter.py | 46 ++++++ 7 files changed, 442 insertions(+), 298 deletions(-) create mode 100644 cogs/benutzerinfo.py create mode 100644 cogs/corona.py create mode 100644 cogs/events.py create mode 100644 cogs/lol.py create mode 100644 cogs/mc.py create mode 100644 cogs/wetter.py diff --git a/bot.py b/bot.py index 44f1b9e..09aa075 100644 --- a/bot.py +++ b/bot.py @@ -6,13 +6,13 @@ import discord.ext import requests from discord.ext import commands -from riotwatcher import LolWatcher -import datetime -import mysql.connector import urllib from urllib import parse import os +from lib.utils import get_variable +from lib import constants + # Wichs Codierung # ä=ü # ö=ö @@ -107,7 +107,7 @@ async def on_ready(): print("MySQL-Logging ist DEAKTIVIERT") print("Der Bot ist zurzeit auf folgenden " + str(len(client.guilds)) + " Servern:") for guild in client.guilds: - print("-" + str(guild.name)) + print("- " + str(guild.name)) client.loop.create_task(status_task()) @@ -131,253 +131,6 @@ async def status_task(): await asyncio.sleep(60) -def benutzerinfo(): - @client.command() - async def benutzerinfo(ctx, member: discord.Member): - embed = discord.Embed(title='Benutzerinfo für {}'.format(member.name), - description='Benutzerinfo für {}'.format( - member.mention), - color=0x69E82C) - embed.add_field(name='Server beigetreten', - value=member.joined_at.strftime('%d/%m/%Y'), - inline=True) - embed.add_field(name='Discord beigetreten', - value=member.created_at.strftime('%d/%m/%Y'), - inline=True) - embed.add_field(name=f"Rollen ({len(member.roles)})", - value=" ".join([role.mention for role in member.roles])) - - rollen = '' - for role in member.roles: - if not role.is_default(): - rollen += '{} \r\n'.format(role.mention) - embed.add_field(name='Höchste Rolle', value=member.top_role.mention, inline=True), - embed.add_field(name="Benutzer ID", value=member.id, inline=True), - embed.set_thumbnail(url=member.avatar_url) - embed.set_footer(text='Benutzerinfo') - await ctx.send(embed=embed) - - -benutzerinfo() - - -def wetter(): - api_key = "7d518678abe248fc7de360ba82f9375b" - base_url = "http://api.openweathermap.org/data/2.5/weather?" - - @client.command() - async def wetter(ctx, *, city: str): - city_name = city - complete_url = base_url + "appid=" + api_key + "&q=" + city_name + "&lang=de" - response = requests.get(complete_url) - x = response.json() - channel = ctx.message.channel - if x["cod"] != "404": - async with channel.typing(): - y = x["main"] - derzeitige_temperatur = y["temp"] - derzeitige_temperatur_celsius = str(round(derzeitige_temperatur - 273.15)) - druck = y["pressure"] - luftfeuchtigkeit = y["humidity"] - fuehlt_sich_an_wie = y["feels_like"] - fuehlt_sich_an_wie_celsius = str(round(fuehlt_sich_an_wie - 273.15)) - z = x["weather"] - symbol = z[0]["icon"] - wetter_beschreibung = z[0]["description"] - embed = discord.Embed(title=f"Wetter in {city_name}", - color=ctx.guild.me.top_role.color, - timestamp=ctx.message.created_at, ) - embed.add_field(name="Beschreibung", value=f"**{wetter_beschreibung}**", inline=False) - embed.add_field(name="Temperatur(C)", value=f"**{derzeitige_temperatur_celsius}°C**", inline=False) - embed.add_field(name="Fühlt sich an wie(C)", value=f"**{fuehlt_sich_an_wie_celsius}°C**", - inline=False) - embed.add_field(name="Luftfeuchtigkeit(%)", value=f"**{luftfeuchtigkeit}%**", inline=False) - embed.add_field(name="Luftdruck(hPa)", value=f"**{druck}hPa**", inline=False) - embed.set_thumbnail(url="http://openweathermap.org/img/wn/" + symbol + ".png") - embed.set_footer(text=f"Angefragt von {ctx.author.name}") - await ctx.send(embed=embed) - else: - await ctx.send("Stadt wurde nicht gefunden.") - - -wetter() - - -def LeagueofLegendsstats(): - with open('./config.json', 'r') as f: - json_stuff = json.load(f) - riotapi = json_stuff["riotapi"] - api_key = riotapi - base_url = "https://euw1.api.riotgames.com/lol/" - - @client.group(invoke_without_command=True) - async def lol(ctx): - embed = discord.Embed(title="League of Legends Statistiken", color=ctx.author.color) - embed.add_field(name="Alle Befehle:", value="Mach help lol um dir alle Befehle anzeigen zu lassen", - inline=False) - embed.set_thumbnail( - url="https://www.riotgames.com/darkroom/original/462106d7bcc8d74a57a49411b70c4a92" - ":d4bed097ee383e5afad037edb5e5786e/lol-logo-rendered-hi-res.png") - embed.set_footer(text='antonstech/antonstechbot ({})'.format(VERSION), icon_url='https://i.imgur.com' - '/gFHBoZA.png') - await ctx.send(embed=embed) - - @lol.command() - async def level(ctx, *, name: str): - spielername = name - complete_url = base_url + "summoner/v4/summoners/by-name/" + spielername + "?api_key=" + api_key - response = requests.get(complete_url) - x = response.json() - channel = ctx.message.channel - if 0 < x["summonerLevel"] < 3000: - async with channel.typing(): - y = x - spielerlevel = y["summonerLevel"] - profilbild = y["profileIconId"] - embed = discord.Embed(title=f"Leauge of Legends Statistiken für {spielername}", - color=ctx.author.color, - timestamp=ctx.message.created_at, ) - embed.add_field(name="Level des Spielers:", value=f"**{spielerlevel}**", inline=False) - embed.set_thumbnail( - url='http://ddragon.leagueoflegends.com/cdn/11.1.1/img/profileicon/' + str(profilbild) + '.png') - await ctx.send(embed=embed) - else: - await ctx.send("Spieler wurde nicht gefunden.") - - @lol.command() - async def rang(ctx, *, name: str): - spielername = name - channel = ctx.message.channel - try: - lol_watcher = LolWatcher(api_key) - my_region = 'euw1' - me = lol_watcher.summoner.by_name(my_region, spielername) - my_ranked_stats = lol_watcher.league.by_summoner(my_region, me['id']) - async with channel.typing(): - if my_ranked_stats: - data = my_ranked_stats[0] - rang = data["tier"] - nummer = data["rank"] - punkte = data["leaguePoints"] - gewonnen = data["wins"] - verloren = data["losses"] - neu_in_der_elo = data["freshBlood"] - winrate = gewonnen / (gewonnen + verloren) * 100 - embed = discord.Embed(title=f"Leauge of Legends Ranked Statistiken für {spielername}", - color=ctx.author.color, - timestamp=ctx.message.created_at, ) - embed.add_field(name="Rang", value=f"{rang} {nummer}", inline=True) - embed.add_field(name="Punkte", value=f"{punkte}", inline=True) - embed.add_field(name="Neu in der Elo?", value=f"{neu_in_der_elo}", inline=True) - embed.add_field(name="Gewonnen:", value=f"{gewonnen}", inline=True) - embed.add_field(name="Verloren:", value=f"{verloren}", inline=True) - embed.add_field(name="Winrate", value=f"{winrate.__round__()}%", inline=True) - embed.set_thumbnail(url="https://antonstech.de/" + str(rang) + ".png") - await ctx.send(embed=embed) - else: - await ctx.send("Spieler nicht gefunden oder nicht eingeranked.") - except: - await ctx.send("Spieler nicht gefunden oder nicht eingeranked.") - - -LeagueofLegendsstats() - - -def mc(): - base_url = "https://api.mcsrvstat.us/2/" - - @client.group(invoke_without_command=True) - async def mc(ctx): - embed = discord.Embed(title="Der Mc Command kann dir viele Nützliche Dinge zum Thema Minecraft anzeigen") - embed.add_field(name="Funktionen:", value="skin, server, name") - await ctx.send(embed=embed) - - @mc.command() - async def server(ctx, *, adresse: str): - complete_url = base_url + adresse - response = requests.get(complete_url) - channel = ctx.message.channel - x = response.json() - async with channel.typing(): - status = x["online"] - embed = discord.Embed(title="Minecraft Server Stats für " + adresse) - if status is True: - try: - modt = x["motd"] - beschreibung = modt["clean"] - modtbeschreibung = beschreibung[0] - spieler = x["players"] - spieleronline = spieler["online"] - slots = spieler["max"] - embed.add_field(name="Beschreibung", value=f"{modtbeschreibung}") - embed.add_field(name="Spieler", value=f"{spieleronline} / {slots}") - try: - version = x["version"] - software = x["software"] - embed.add_field(name="Version", value=f"{software} {version}") - except: - embed.add_field(name="Version", value="Info nicht vorhanden") - try: - mods = x["mods"] - modss = mods["names"] - if modss != "": - embed.set_author(name="Modlist", - url='https://mcsrvstat.us/server/' + adresse) - embed.add_field(name="Modlist", value="Siehe oben links") - else: - pass - except: - pass - embed.add_field(name="Online?", value="Jap") - embed.set_thumbnail(url="https://api.mcsrvstat.us/icon/" + adresse) - await ctx.send(embed=embed) - except: - embed.add_field(name="Test", value="Test123") - await ctx.send(embed=embed) - else: - embed.set_footer(text="Der Server ist derzeit nicht online") - await ctx.send(embed=embed) - - @mc.command() - async def skin(ctx, name): - uuid = "https://api.mojang.com/users/profiles/minecraft/" + name - response = requests.get(uuid) - x = response.json() - playeruuid = x["id"] - kopf = "https://crafatar.com/avatars/" - body = "https://crafatar.com/renders/body/" - embed = discord.Embed(title="Minecraft Skin von " + name) - embed.set_thumbnail(url=kopf + playeruuid + "?size=50") - embed.set_image(url=body + playeruuid + "?size=512") - embed.set_author(name="Skin Download", url="https://minotar.net/download/" + name) - await ctx.send(embed=embed) - - @mc.command() - async def name(ctx, name): - embed = discord.Embed(title="Minecraft Namehistory für " + name) - try: - uuid = "https://api.mojang.com/users/profiles/minecraft/" + name - response = requests.get(uuid) - x = response.json() - playeruuid = x["id"] - namehistory = "https://api.mojang.com/user/profiles/" + playeruuid + "/names" - response2 = requests.get(namehistory) - y = response2.json() - try: - namen = y[0]["name"] - embed.add_field(name="Namensänderung:", value=f"**{namen}** --> **{name}**") - except: - pass - except: - embed.add_field(name="Spieler Nicht gefunden", - value="Schau mal nach ob du alles richtig geschrieben hast. Und falls es dann immernoch " - "nicht geht Kontaktier bitte den Entwickler des Bots") - await ctx.send(embed=embed) - - -mc() - - def corona(): @client.group(invoke_without_command=True) async def corona(ctx): @@ -406,8 +159,8 @@ async def corona(ctx): embed.add_field(name="Fälle insgesammt", value=f"{insgesamt}") embed.add_field(name="Tode insgesamt", value=f"{todegesamt}") embed.add_field(name="Gesund", value=f"{gesund}") - embed.add_field(name="Inzidenz", value=f"{inzidenz.__round__()}") - embed.add_field(name="Geimpft", value=f"{jetzgeimpft.__round__(3) * 100}%") + embed.add_field(name="Inzidenz", value=f"{round(inzidenz, 2)}") + embed.add_field(name="Geimpft", value=f"{round(jetzgeimpft, 2) * 100}%") embed.add_field(name="R-Wert", value=f"{rwert}") embed.set_footer(text="Mit " + prefix + "corona geimpft gibts mehr zur Impfung") await ctx.send(embed=embed) @@ -435,7 +188,7 @@ async def geimpft(ctx): await ctx.send(embed=embed) embed = discord.Embed(title="Statistiken zur Impfung in Deutschland", color=ctx.author.color) - embed.add_field(name="Prozent der Bevölkerung", value=f"{jetztgeimpft.__round__(3) * 100}%") + embed.add_field(name="Prozent der Bevölkerung", value=f"{round(jetztgeimpft, 2) * 100}%") embed.add_field(name="Anzahl der Geimpften", value=f"{gesamt} Personen", inline=False) embed.add_field(name="Zweite Impfung haben bereits erhalten", value=f"{zweite_imfung} Personen") await ctx.send(embed=embed) @@ -799,57 +552,66 @@ async def opgoldapfel(ctx, member: discord.Member): give() +""" +############################################################################################################################################################## + Ole rewrite paradise +############################################################################################################################################################## +""" -use_mysql = False - -if os.path.exists("mysql.json"): - with open('mysql.json', 'r') as f: - json_stuff = json.load(f) - host = json_stuff["host"] - user = json_stuff["user"] - passwort = json_stuff["passwort"] - datenbank = json_stuff["datenbank"] - port = json_stuff["port"] - tablename = json_stuff["tablename"] - use_mysql = True - - - -else: - pass - - -async def sql_connection_stuff(message): - if not use_mysql: - return - mydb = mysql.connector.connect( - host=host, - user=user, - password=passwort, - database=datenbank, - port=port) - zeit = datetime.datetime.now() - zeit_srftime = zeit.strftime("%Y-%m-%d %H:%M:%S") - sql = "INSERT INTO " + tablename + "(time, content, attachement, membername, memberid, guildid, guildname, channelid, \ - channelname, id) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s) " - val = [ - (f"{zeit_srftime}", f"{message.content}", f"{message.attachments}", f"{message.author}", - f"{message.author.id}", f"{message.guild.id}", f"{message.guild}", - f"{message.channel.id}", f"{message.channel}", f"{message.id}") - ] - mycursor = mydb.cursor() - mycursor.executemany(sql, val) - mydb.commit() +def owner_only(func): + async def wrapper(self, *args, **kwargs): + ctx = get_variable('ctx') + info = await client.application_info() + if ctx.author.id == info.owner.id: + return await func(self, *args, **kwargs) + else: + await ctx.send("Error, only the bot owner can use this command!") + + return wrapper + + +@client.command(name="reload") +@owner_only +async def reload_cog(ctx, cogName): + try: + await unload_cog(ctx, cogName) + await load_cog(ctx, cogName) + except Exception as e: + await ctx.channel.send(f"Während dem versuch die Erweiterung {cogName} neu zu laden ist etwas schiefgelaufen!") + + +@client.command(name="unload") +@owner_only +async def unload_cog(ctx, cogName): + try: + client.unload_extension(f"cogs.{cogName}") + await ctx.channel.send(f"Erfolgreich erweiterung {cogName} entladen!") + except Exception as e: + await ctx.channel.send(f"Fehler, entweder ist die erweiterung schong entladen, oder sie wurde nicht gefunden!") + + +@client.command(name="load") +@owner_only +async def load_cog(ctx, cogName): + try: + client.load_extension(f"cogs.{cogName}") + await ctx.channel.send(f"Erfolgreich erweiterung {cogName} geladen!") + except Exception as e: + await ctx.channel.send(f"Fehler, entweder ist die erweiterung schon geladen, oder sie wurde nicht gefunden.") -@client.event -async def on_message(message): - asyncio.ensure_future(sql_connection_stuff(message)) - await client.process_commands(message) with open('config.json', 'r') as f: json_stuff = json.load(f) token = json_stuff["token"] +# load cogs +for filename in os.listdir("./cogs"): + if filename.endswith(".py"): + client.load_extension(f"cogs.{filename[:-3]}") + +# assign constant variables +constants.assignVariables() +# run bot client.run(token) diff --git a/cogs/benutzerinfo.py b/cogs/benutzerinfo.py new file mode 100644 index 0000000..1c23f72 --- /dev/null +++ b/cogs/benutzerinfo.py @@ -0,0 +1,36 @@ +from discord.ext import commands +import discord + + +class Benutzerinfo(commands.Cog): + def __init__(self, client): + self.client = client + + @commands.command(name="benutzerinfo") + async def benutzerinfo_command(self, ctx, member: discord.Member): + embed = discord.Embed(title='Benutzerinfo für {}'.format(member.name), + description='Benutzerinfo für {}'.format( + member.mention), + color=0x69E82C) + embed.add_field(name='Server beigetreten', + value=member.joined_at.strftime('%d/%m/%Y'), + inline=True) + embed.add_field(name='Discord beigetreten', + value=member.created_at.strftime('%d/%m/%Y'), + inline=True) + embed.add_field(name=f"Rollen ({len(member.roles)})", + value=" ".join([role.mention for role in member.roles])) + + rollen = '' + for role in member.roles: + if not role.is_default(): + rollen += '{} \r\n'.format(role.mention) + embed.add_field(name='Höchste Rolle', value=member.top_role.mention, inline=True), + embed.add_field(name="Benutzer ID", value=member.id, inline=True), + embed.set_thumbnail(url=member.avatar_url) + embed.set_footer(text='Benutzerinfo') + await ctx.send(embed=embed) + + +def setup(client): + client.add_cog(Benutzerinfo(client)) diff --git a/cogs/corona.py b/cogs/corona.py new file mode 100644 index 0000000..b974c79 --- /dev/null +++ b/cogs/corona.py @@ -0,0 +1,52 @@ +from discord.ext import commands +import discord +import requests +from lib import constants + + +class Corona(commands.Cog): + def __init__(self, client): + self.client = client + + @commands.command(name="corona") + async def corona_command(self, ctx, option=None): + + if option is None: + url = "https://api.corona-zahlen.org/germany" + response = requests.get(url).json() + g_url = "https://api.corona-zahlen.org/vaccinations" + geimpft = requests.get(g_url) + y = geimpft.json() + channel = ctx.message.channel + async with channel.typing(): + insgesamt = response["cases"] + todegesamt = response["deaths"] + inzidenz = response["weekIncidence"] + data = y["data"] + jetzgeimpft = data["quote"] + infor = response["r"] + rwert = infor["value"] + gesund = response["recovered"] + embed = discord.Embed(title="Impfen lassen", url="https://antonstech.de/impfung.html", + color=ctx.author.color) + await ctx.send(embed=embed) + embed = discord.Embed(title="Corona Virus Statistiken für Deutschland", + color=ctx.author.color, + timestamp=ctx.message.created_at) + embed.add_field(name="Fälle insgesammt", value=f"{insgesamt}") + embed.add_field(name="Tode insgesamt", value=f"{todegesamt}") + embed.add_field(name="Gesund", value=f"{gesund}") + embed.add_field(name="Inzidenz", value=f"{round(inzidenz, 2)}") + embed.add_field(name="Geimpft", value=f"{round(jetzgeimpft, 2) * 100}%") + embed.add_field(name="R-Wert", value=f"{rwert}") + embed.set_footer(text="Mit " + constants.prefix + "corona geimpft gibts mehr zur Impfung") + await ctx.send(embed=embed) + embed = discord.Embed(title="Aktuelle Corona Map für Deutschland", + color=ctx.author.color, + timestamp=ctx.message.created_at) + embed.set_image(url="https://api.corona-zahlen.org/map/districts") + embed.set_footer(text="Mit " + constants.prefix + "corona geimpft gibts mehr zur Impfung") + await ctx.send(embed=embed) + +def setup(client): + client.add_cog(Corona(client)) diff --git a/cogs/events.py b/cogs/events.py new file mode 100644 index 0000000..828e5ec --- /dev/null +++ b/cogs/events.py @@ -0,0 +1,52 @@ +from discord.ext import commands +import os +import json +import mysql.connector +import datetime +import asyncio + + +class Events(commands.Cog): + def __init__(self, client): + self.client = client + self.use_mysql = False + if os.path.exists("mysql.json"): + with open('mysql.json', 'r') as f: + json_stuff = json.load(f) + self.host = json_stuff["host"] + self. user = json_stuff["user"] + self.passwort = json_stuff["passwort"] + self.datenbank = json_stuff["datenbank"] + self.port = json_stuff["port"] + self.tablename = json_stuff["tablename"] + self.use_mysql = True + + async def sql_connection_stuff(self, message): + if not self.use_mysql: + return + mydb = mysql.connector.connect( + host=self.host, + user=self.user, + password=self.passwort, + database=self.datenbank, + port=self.port) + zeit = datetime.datetime.now() + zeit_srftime = zeit.strftime("%Y-%m-%d %H:%M:%S") + sql = "INSERT INTO " + self.tablename + "(time, content, attachement, membername, memberid, guildid, guildname, channelid, \ + channelname, id) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s) " + val = [ + (f"{zeit_srftime}", f"{message.content}", f"{message.attachments}", f"{message.author}", + f"{message.author.id}", f"{message.guild.id}", f"{message.guild}", + f"{message.channel.id}", f"{message.channel}", f"{message.id}") + ] + mycursor = mydb.cursor() + mycursor.executemany(sql, val) + mydb.commit() + + @commands.Cog.listener + async def on_message(self, message): + asyncio.ensure_future(self.sql_connection_stuff(message)) + + +def setup(client): + client.add_cog(Events(client)) diff --git a/cogs/lol.py b/cogs/lol.py new file mode 100644 index 0000000..8f71e68 --- /dev/null +++ b/cogs/lol.py @@ -0,0 +1,92 @@ +from discord.ext import commands +import discord +import json +import requests +from lib import constants +from riotwatcher import LolWatcher + + +class Lol(commands.Cog): + def __init__(self, client): + self.client = client + with open('./config.json', 'r') as f: + json_stuff = json.load(f) + self.api_key = json_stuff["riotapi"] + self.base_url = "https://euw1.api.riotgames.com/lol/" + + @commands.Cog.listener() + async def on_ready(self): + print("lolcommand hat geladen") + + @commands.command(name="lol") + async def lol_command(self, ctx, option=None, username=None): + + if option is None: + embed = discord.Embed(title="League of Legends Statistiken", color=ctx.author.color) + embed.add_field(name="Alle Befehle:", value="Mach help lol um dir alle Befehle anzeigen zu lassen", + inline=False) + embed.set_thumbnail( + url="https://www.riotgames.com/darkroom/original/462106d7bcc8d74a57a49411b70c4a92" + ":d4bed097ee383e5afad037edb5e5786e/lol-logo-rendered-hi-res.png") + embed.set_footer(text='antonstech/antonstechbot ({})'.format(constants.VERSION), icon_url='https://i.imgur.com' + '/gFHBoZA.png') + await ctx.send(embed=embed) + + return + + if option == "level": + complete_url = self.base_url + "summoner/v4/summoners/by-name/" + username + "?api_key=" + self.api_key + response = requests.get(complete_url).json() + channel = ctx.message.channel + if 0 < response["summonerLevel"] < 3000: + async with channel.typing(): + spielerlevel = response["summonerLevel"] + profilbild = response["profileIconId"] + embed = discord.Embed(title=f"Leauge of Legends Statistiken für {username}", + color=ctx.author.color, + timestamp=ctx.message.created_at, ) + embed.add_field(name="Level des Spielers:", value=f"**{spielerlevel}**", inline=False) + embed.set_thumbnail( + url='http://ddragon.leagueoflegends.com/cdn/11.1.1/img/profileicon/' + str(profilbild) + '.png') + await ctx.send(embed=embed) + else: + await ctx.send("Spieler wurde nicht gefunden.") + + return + + if option == "rang": + channel = ctx.message.channel + try: + lol_watcher = LolWatcher(self.api_key) + my_region = 'euw1' + me = lol_watcher.summoner.by_name(my_region, username) + my_ranked_stats = lol_watcher.league.by_summoner(my_region, me['id']) + async with channel.typing(): + if my_ranked_stats: + data = my_ranked_stats[0] + rang = data["tier"] + nummer = data["rank"] + punkte = data["leaguePoints"] + gewonnen = data["wins"] + verloren = data["losses"] + neu_in_der_elo = data["freshBlood"] + winrate = gewonnen / (gewonnen + verloren) * 100 + embed = discord.Embed(title=f"Leauge of Legends Ranked Statistiken für {username}", + color=ctx.author.color, + timestamp=ctx.message.created_at, ) + embed.add_field(name="Rang", value=f"{rang} {nummer}", inline=True) + embed.add_field(name="Punkte", value=f"{punkte}", inline=True) + embed.add_field(name="Neu in der Elo?", value=f"{neu_in_der_elo}", inline=True) + embed.add_field(name="Gewonnen:", value=f"{gewonnen}", inline=True) + embed.add_field(name="Verloren:", value=f"{verloren}", inline=True) + embed.add_field(name="Winrate", value=f"{round(winrate, 2)}%", inline=True) + embed.set_thumbnail(url="https://antonstech.de/" + str(rang) + ".png") + await ctx.send(embed=embed) + else: + await ctx.send("Spieler nicht gefunden oder nicht eingeranked.") + except: + await ctx.send("Spieler nicht gefunden oder nicht eingeranked.") + + +def setup(client): + client.add_cog(Lol(client)) diff --git a/cogs/mc.py b/cogs/mc.py new file mode 100644 index 0000000..f19ab9c --- /dev/null +++ b/cogs/mc.py @@ -0,0 +1,104 @@ +from discord.ext import commands +import discord +import requests + + +class Mc(commands.Cog): + def __init__(self, client): + self.client = client + self.base_url = "https://api.mcsrvstat.us/2/" + + @commands.command(name="mc") + async def mc_command(self, ctx, option=None, arg1=None): + + if option is None: + embed = discord.Embed(title="Der Mc Command kann dir viele Nützliche Dinge zum Thema Minecraft anzeigen") + embed.add_field(name="Funktionen:", value="skin, server, name") + await ctx.send(embed=embed) + return + + if arg1 is None: + await ctx.send("Fehler: Gebe etwas an wonach du suchst!") + + elif option == "server": + complete_url = self.base_url + arg1 + response = requests.get(complete_url).json() + channel = ctx.message.channel + async with channel.typing(): + status = response["online"] + embed = discord.Embed(title="Minecraft Server Stats für " + arg1) + if status is True: + try: + modt = response["motd"] + beschreibung = modt["clean"] + modtbeschreibung = beschreibung[0] + spieler = response["players"] + spieleronline = spieler["online"] + slots = spieler["max"] + embed.add_field(name="Beschreibung", value=f"{modtbeschreibung}") + embed.add_field(name="Spieler", value=f"{spieleronline} / {slots}") + try: + version = response["version"] + software = response["software"] + embed.add_field(name="Version", value=f"{software} {version}") + except: + embed.add_field(name="Version", value="Info nicht vorhanden") + try: + mods = response["mods"] + modss = mods["names"] + if modss != "": + embed.set_author(name="Modlist", + url='https://mcsrvstat.us/server/' + arg1) + embed.add_field(name="Modlist", value="Siehe oben links") + else: + pass + except: + pass + embed.add_field(name="Online?", value="Jap") + embed.set_thumbnail(url="https://api.mcsrvstat.us/icon/" + arg1) + await ctx.send(embed=embed) + except: + embed.add_field(name="Test", value="Test123") + await ctx.send(embed=embed) + else: + embed.set_footer(text="Der Server ist derzeit nicht online") + await ctx.send(embed=embed) + return + + elif option == "skin": + uuid = "https://api.mojang.com/users/profiles/minecraft/" + arg1 + response = requests.get(uuid) + x = response.json() + playeruuid = x["id"] + kopf = "https://crafatar.com/avatars/" + body = "https://crafatar.com/renders/body/" + embed = discord.Embed(title="Minecraft Skin von " + arg1) + embed.set_thumbnail(url=kopf + playeruuid + "?size=50") + embed.set_image(url=body + playeruuid + "?size=512") + embed.set_author(name="Skin Download", url="https://minotar.net/download/" + arg1) + await ctx.send(embed=embed) + return + + elif option == "name": + embed = discord.Embed(title="Minecraft Namehistory für " + arg1) + try: + uuid = "https://api.mojang.com/users/profiles/minecraft/" + arg1 + response = requests.get(uuid).json() + playeruuid = response["id"] + namehistory = "https://api.mojang.com/user/profiles/" + playeruuid + "/names" + response2 = requests.get(namehistory).json() + try: + namen = response2[0]["name"] + embed.add_field(name="Namensänderung:", value=f"**{namen}** --> **{arg1}**") + except: + pass + except: + embed.add_field(name="Spieler Nicht gefunden", + value="Schau mal nach ob du alles richtig geschrieben hast. Und falls es dann immernoch " + "nicht geht Kontaktier bitte den Entwickler des Bots") + await ctx.send(embed=embed) + return + + +def setup(client): + client.add_cog(Mc(client)) diff --git a/cogs/wetter.py b/cogs/wetter.py new file mode 100644 index 0000000..edef695 --- /dev/null +++ b/cogs/wetter.py @@ -0,0 +1,46 @@ +from discord.ext import commands +import discord +import requests + + +class Wetter(commands.Cog): + def __init__(self, client): + self.client = client + self.api_key = "7d518678abe248fc7de360ba82f9375b" + self.base_url = "http://api.openweathermap.org/data/2.5/weather?" + + @commands.command(name="wetter") + async def wetter_command(self, ctx, city): + complete_url = self.base_url + "appid=" + self.api_key + "&q=" + city + "&lang=de" + response = requests.get(complete_url).json() + channel = ctx.message.channel + if response["cod"] != "404": + async with channel.typing(): + y = response["main"] + derzeitige_temperatur = y["temp"] + derzeitige_temperatur_celsius = str(round(derzeitige_temperatur - 273.15)) + druck = y["pressure"] + luftfeuchtigkeit = y["humidity"] + fuehlt_sich_an_wie = y["feels_like"] + fuehlt_sich_an_wie_celsius = str(round(fuehlt_sich_an_wie - 273.15)) + z = response["weather"] + symbol = z[0]["icon"] + wetter_beschreibung = z[0]["description"] + embed = discord.Embed(title=f"Wetter in {city}", + color=ctx.guild.me.top_role.color, + timestamp=ctx.message.created_at, ) + embed.add_field(name="Beschreibung", value=f"**{wetter_beschreibung}**", inline=False) + embed.add_field(name="Temperatur(C)", value=f"**{derzeitige_temperatur_celsius}°C**", inline=False) + embed.add_field(name="Fühlt sich an wie(C)", value=f"**{fuehlt_sich_an_wie_celsius}°C**", + inline=False) + embed.add_field(name="Luftfeuchtigkeit(%)", value=f"**{luftfeuchtigkeit}%**", inline=False) + embed.add_field(name="Luftdruck(hPa)", value=f"**{druck}hPa**", inline=False) + embed.set_thumbnail(url="http://openweathermap.org/img/wn/" + symbol + ".png") + embed.set_footer(text=f"Angefragt von {ctx.author.name}") + await ctx.send(embed=embed) + else: + await ctx.send("Stadt wurde nicht gefunden.") + + +def setup(client): + client.add_cog(Wetter(client)) From 16472cc00c6ebee603d3680958787522d73828c7 Mon Sep 17 00:00:00 2001 From: DestinyofYeet Date: Wed, 17 Mar 2021 09:51:17 +0100 Subject: [PATCH 2/9] moved commands to cog, created lib folder, created config folder and moved config in there --- .gitignore | 3 +- bot.py | 465 +----------------- cogs/anime.py | 52 ++ cogs/commands.py | 63 +++ cogs/corona.py | 31 +- cogs/earth2.py | 27 + cogs/events.py | 2 +- cogs/give.py | 49 ++ cogs/hilfe.py | 51 ++ cogs/ip.py | 43 ++ cogs/lol.py | 12 +- cogs/osu.py | 46 ++ .../config.json.example | 0 .../mysql.json.example | 0 lib/__init__.py | 0 lib/constants.py | 25 + lib/help.json | 61 +++ lib/utils.py | 16 + start.py | 10 +- 19 files changed, 484 insertions(+), 472 deletions(-) create mode 100644 cogs/anime.py create mode 100644 cogs/commands.py create mode 100644 cogs/earth2.py create mode 100644 cogs/give.py create mode 100644 cogs/hilfe.py create mode 100644 cogs/ip.py create mode 100644 cogs/osu.py rename config.json.example => config/config.json.example (100%) rename mysql.json.example => config/mysql.json.example (100%) create mode 100644 lib/__init__.py create mode 100644 lib/constants.py create mode 100644 lib/help.json create mode 100644 lib/utils.py diff --git a/.gitignore b/.gitignore index 12f8124..eb08ce2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ archiv/ -config.json +config/config.json .idea mysql.json disabled_mysql.json @@ -21,7 +21,6 @@ dist/ downloads/ eggs/ .eggs/ -lib/ lib64/ parts/ sdist/ diff --git a/bot.py b/bot.py index 09aa075..615b201 100644 --- a/bot.py +++ b/bot.py @@ -6,8 +6,6 @@ import discord.ext import requests from discord.ext import commands -import urllib -from urllib import parse import os from lib.utils import get_variable @@ -17,19 +15,18 @@ # ä=ü # ö=ö -VERSION = subprocess.check_output(["git", "describe", "--tags", "--always"]).decode('ascii').strip() +# assign constant variables +constants.assignVariables() -with open('./config.json', 'r') as f: - json_stuff = json.load(f) - prefix = json_stuff["prefix"] +VERSION = constants.VERSION -client = commands.Bot(command_prefix=prefix, intents=discord.Intents.all()) +bot_prefix = constants.bot_prefix + +client = commands.Bot(command_prefix=bot_prefix, intents=discord.Intents.all()) def tokenchecker(): - with open('./config.json', 'r') as f: - json_stuff = json.load(f) - riotapi = json_stuff["riotapi"] + riotapi = constants.lol_token base_riot_url = "https://euw1.api.riotgames.com/lol/summoner/v4/summoners/by-name/DCGALAXY?api_key=" rioturl = base_riot_url + riotapi response = requests.get(rioturl) @@ -46,9 +43,7 @@ def tokenchecker(): else: raise Exception("Der Riot-API Key hat nicht funktioniert.") - with open('./config.json', 'r') as f: - json_stuff = json.load(f) - osuapi = json_stuff["osuapi"] + osuapi = constants.osu_token base_osu_url = "https://osu.ppy.sh/api/get_user_best?u=Aftersh0ock&k=" osuurl = base_osu_url + osuapi osuresponse = requests.get(osuurl) @@ -63,9 +58,7 @@ def tokenchecker(): pass else: raise Exception("Der Osu-API Key hat nicht funktioniert.") - with open('config.json', 'r') as f: - json_stuff = json.load(f) - token = json_stuff["token"] + token = constants.bot_token headers = { "Authorization": "Bot " + token } @@ -74,9 +67,7 @@ def tokenchecker(): pass else: raise Exception("Der Discord Bot Token funktioniert nicht!") - with open('./config.json', 'r') as f: - json_stuff = json.load(f) - ipdata = json_stuff["ipdata"] + ipdata = constants.ipdata_token baseipurl = "https://api.ipdata.co/8.8.8.8" ipurl = baseipurl + "?api-key=" + ipdata ipresponse = requests.get(ipurl) @@ -111,18 +102,13 @@ async def on_ready(): client.loop.create_task(status_task()) -with open('./config.json', 'r') as f: - json_stuff = json.load(f) - prefix = json_stuff["prefix"] - - async def status_task(): while True: await client.change_presence(activity=discord.Game("https://git.io/antonsbot"), status=discord.Status.online) await asyncio.sleep(60) await client.change_presence( - activity=discord.Game(prefix + "corona auf " + str(len(client.guilds)) + " Servern")) + activity=discord.Game(bot_prefix + "corona auf " + str(len(client.guilds)) + " Servern")) await asyncio.sleep(60) await client.change_presence(activity=discord.Game("ein heißes Spiel mit der Stiefschwester")) await asyncio.sleep(5) @@ -130,428 +116,6 @@ async def status_task(): activity=discord.Activity(type=discord.ActivityType.watching, name="auf deine Nachrichten")) await asyncio.sleep(60) - -def corona(): - @client.group(invoke_without_command=True) - async def corona(ctx): - url = "https://api.corona-zahlen.org/germany" - response = requests.get(url) - x = response.json() - g_url = "https://api.corona-zahlen.org/vaccinations" - geimpft = requests.get(g_url) - y = geimpft.json() - channel = ctx.message.channel - async with channel.typing(): - insgesamt = x["cases"] - todegesamt = x["deaths"] - inzidenz = x["weekIncidence"] - data = y["data"] - jetzgeimpft = data["quote"] - infor = x["r"] - rwert = infor["value"] - gesund = x["recovered"] - embed = discord.Embed(title="Impfen lassen", url="https://antonstech.de/impfung.html", - color=ctx.author.color) - await ctx.send(embed=embed) - embed = discord.Embed(title="Corona Virus Statistiken für Deutschland", - color=ctx.author.color, - timestamp=ctx.message.created_at) - embed.add_field(name="Fälle insgesammt", value=f"{insgesamt}") - embed.add_field(name="Tode insgesamt", value=f"{todegesamt}") - embed.add_field(name="Gesund", value=f"{gesund}") - embed.add_field(name="Inzidenz", value=f"{round(inzidenz, 2)}") - embed.add_field(name="Geimpft", value=f"{round(jetzgeimpft, 2) * 100}%") - embed.add_field(name="R-Wert", value=f"{rwert}") - embed.set_footer(text="Mit " + prefix + "corona geimpft gibts mehr zur Impfung") - await ctx.send(embed=embed) - embed = discord.Embed(title="Aktuelle Corona Map für Deutschland", - color=ctx.author.color, - timestamp=ctx.message.created_at) - embed.set_image(url="https://api.corona-zahlen.org/map/districts") - embed.set_footer(text="Mit " + prefix + "corona geimpft gibts mehr zur Impfung") - await ctx.send(embed=embed) - - @corona.command(invoke_without_command=True) - async def geimpft(ctx): - url = "https://api.corona-zahlen.org/vaccinations" - response = requests.get(url) - x = response.json() - channel = ctx.message.channel - async with channel.typing(): - y = x["data"] - jetztgeimpft = y["quote"] - gesamt = y["vaccinated"] - second = y["secondVaccination"] - zweite_imfung = second["vaccinated"] - embed = discord.Embed(title="Impfen lassen", url="https://antonstech.de/impfung.html", - color=ctx.author.color) - await ctx.send(embed=embed) - embed = discord.Embed(title="Statistiken zur Impfung in Deutschland", - color=ctx.author.color) - embed.add_field(name="Prozent der Bevölkerung", value=f"{round(jetztgeimpft, 2) * 100}%") - embed.add_field(name="Anzahl der Geimpften", value=f"{gesamt} Personen", inline=False) - embed.add_field(name="Zweite Impfung haben bereits erhalten", value=f"{zweite_imfung} Personen") - await ctx.send(embed=embed) - - -corona() - - -def osu(): - with open('./config.json', 'r') as f: - json_stuff = json.load(f) - osuapi = json_stuff["osuapi"] - url = "https://osu.ppy.sh/api/get_user?u=" - - @client.command() - async def osu(ctx, name): - try: - spielerstats = url + name + "&k=" + osuapi - response = requests.get(spielerstats) - x = response.json() - y = x[0] - userid = y["user_id"] - playedgames = y["playcount"] - level = y["level"] - levelgerundet = (int(float(level))) - spielzeit_sekunden = y["total_seconds_played"] - spielzeit_stunden = int(spielzeit_sekunden) / 3600 - genauigkeit = y["accuracy"] - genauigkeit_int = (int(float(genauigkeit))) - globalrank = y["pp_rank"] - localrank = y["pp_country_rank"] - land = y["country"] - embed = discord.Embed(title="Osu Stats für " + name) - embed.set_thumbnail(url="http://s.ppy.sh/a/" + userid) - embed.add_field(name="Gespielte Spiele", value=f"{playedgames}") - embed.add_field(name="Level", value=f"{levelgerundet}") - embed.add_field(name="Spielzeit", value=f"{(int(float(spielzeit_stunden)))} Stunden") - embed.add_field(name="Genauigkeit", value=f"{genauigkeit_int.__round__()}%") - embed.add_field(name="Globaler Rang", value=f"{globalrank}") - embed.add_field(name="Rang in " + land, value=f"{localrank}") - await ctx.send(embed=embed) - except: - await ctx.send( - "Irgendetwas ist schief gelaufen; check ob der Name richtig geschrieben ist und falls es dann nicht geht Kontaktiere DCGALAXY#9729") - - -osu() - - -def earth2(): - @client.command() - async def earth2(ctx): - url = "https://earth2stats.net/api/get_countries/199" - response = requests.get(url) - x = response.json() - land = x["name"] - wert = x["marketplace_tile_value"] - verkauft = x["total_sold_tiles"] - embed = discord.Embed(title="Earth2 Statistiken für " + land, url="https://earth2stats.net/country/" + land) - embed.set_thumbnail( - url="https://static-cdn.jtvnw.net/jtv_user_pictures/99783da2-3f60-4aeb-92bd-83e953c03627-profile_image-70x70.png") - embed.add_field(name="Wert eines Tiles", value=f"{wert}E$") - embed.add_field(name="Insgesamt verkauft", value=f"{verkauft} Tiles") - await ctx.send(embed=embed) - - -earth2() - - -def anime(): - @client.command() - async def anime(ctx): - base_url = "https://trace.moe/api/search?url=" - attachment = ctx.message.attachments[0] - attachementurl = attachment.url - url = base_url + attachementurl - response = requests.post(url) - x = response.json() - y = x["docs"][0] - genauigkeit = y["similarity"] - hentai = y["is_adult"] - titel = y["title_english"] - nativetitel = y["title_native"] - anilist = y["anilist_id"] - filename = y["filename"] - at = y["at"] - tokenthumb = y["tokenthumb"] - ### Coming Soon - filenameencoded = urllib.parse.quote(filename) - imgrequest = "https://media.trace.moe/image/" + str(anilist) + "/" + filenameencoded + "?t=" + str( - at) + "&token=" + tokenthumb + "&size=m" - ### - if titel != None: - embed = discord.Embed(title=f"{titel}") - else: - embed = discord.Embed(title=f"{nativetitel}") - anilisturl = "https://anilist.co/anime/" + str(anilist) - embed.set_author(name="Anilist Link", url=anilisturl) - embed.add_field(name="Genauigkeit", value=f"{(genauigkeit * 100).__round__()}%") - if hentai == False: - embed.add_field(name="Hentai?", value="Nope :(") - else: - embed.add_field(name="Hentai?", value="Yess Sir") - if titel != None: - embed.add_field(name="Titel in Orginalsprache", value=f"{nativetitel}") - else: - pass - embed.set_image(url=str(imgrequest)) - await ctx.send(embed=embed) - - -anime() - - -def ipdata(): - with open('./config.json', 'r') as f: - json_stuff = json.load(f) - ipdata = json_stuff["ipdata"] - url = "https://api.ipdata.co/" - - @client.command() - async def ip(ctx, ip): - apiurl = "?api-key=" + ipdata - resulturl = url + ip + apiurl - response = requests.get(resulturl) - x = response.json() - city = x["city"] - country = x["country_name"] - flag = x["flag"] - y = x["asn"] - asn = y["name"] - asntype = y["type"] - postleitzahl = x["postal"] - kontinent = x["continent_name"] - embed = discord.Embed(title="IP Informationen zu " + ip) - embed.set_thumbnail(url=flag) - embed.add_field(name="Land", value=f"{country}") - embed.add_field(name="Stadt", value=f"{city}") - embed.add_field(name="Kontinent", value=f"{kontinent}") - if postleitzahl == None: - pass - else: - embed.add_field(name="Postleitzahl", value=f"{postleitzahl}") - embed.add_field(name="Internetanbieter", value=f"{asn}") - embed.add_field(name="Anbiter-Type", value=f"{asntype}") - await ctx.send(embed=embed) - - -ipdata() - - -@client.command(invoke_without_command=True) -async def ping(ctx): - await ctx.send("Der Ping beträgt derzeit " f"{round(client.latency * 1000)}ms") - - -@client.command(invoke_without_command=True) -async def version(ctx): - await ctx.send( - "Der Bot läuft derzeit auf Release " + str(VERSION) + " und geht auch dank discord.py Version {}".format( - discord.__version__)) - - -@client.command(invite_without_command=True) -async def einladen(ctx): - embed = discord.Embed() - embed.set_author(name="Klicke hier zum einladen", - url='https://discord.com/api/oauth2/authorize?client_id=744218316167708773&permissions=8&scope=bot') - await ctx.send(embed=embed) - - -@client.command(invite_without_command=True) -async def hosten(ctx): - embed = discord.Embed() - embed.set_author(name="Klicke hier um ein Tutorial zum Selber hosten zu bekommen", - url='https://github.com/antonstech/antonstechbot/wiki/Installation') - await ctx.send(embed=embed) - - -@client.command(invite_without_command=True) -async def code(ctx): - embed = discord.Embed() - embed.set_author(name="Hier findest du den ganzen Code vom Bot", - url='https://github.com/antonstech/antonstechbot') - await ctx.send(embed=embed) - - -def clear(): - def ist_gepinnt(mess): - return not mess.pinned - - @client.command() - @commands.has_permissions(manage_messages=True) - async def clear(ctx, amount=5): - await ctx.channel.purge(limit=amount + 1, check=ist_gepinnt) - - @clear.error - async def clear_error(ctx, error): - if isinstance(error, commands.MissingPermissions): - await ctx.channel.send("Du hast keine Berechtigung dazu!") - - -clear() - - -@client.command() -async def nudes(ctx): - if ctx.channel.is_nsfw(): - embed = discord.Embed(title="Nudes") - embed.set_image( - url="https://www.nydailynews.com/resizer/OYta-jTp2D6Xt_Wj_o6zEUqWttE=/415x562/top/arc-anglerfish-arc2-prod-tronc.s3.amazonaws.com/public/7Y53KJVE7FGLZZPD44LTN4QB5I.jpg") - await ctx.send(embed=embed) - else: - await ctx.channel.send("Der Channel ist nicht nsfw") - - -def hilfe(): - @client.group(invoke_without_command=True) - async def hilfe(ctx): - embed = discord.Embed(title="Hilfe", - description="Benutze " + prefix + "hilfe (command) für mehr Informationen zu einem Command.", - color=ctx.author.color) - embed.add_field(name="Moderation:", value="clear") - embed.add_field(name="nützlich:", value="wetter, benutzerinfo , ping, anime", inline=True) - embed.add_field(name="fun", value="give, corona, earth2", inline=True) - embed.add_field(name="Game-Stats", value="lol, osu", inline=True) - embed.add_field(name="Minecraft Zeugs", value="mc", inline=True) - embed.add_field(name="Infos zum Bot", value="version, einladen, hosten, code", inline=True) - embed.set_footer(text='Bei sonstigen Fragen einfach DCGALAXY#9729 anschreiben') - await ctx.send(embed=embed) - - @hilfe.command() - async def wetter(ctx): - embed = discord.Embed(title="clear", - description="Mit " + prefix + "wetter kannst du dir das Wetter so wie einige Infos dazu anzeigen lassen", - color=ctx.author.color) - embed.add_field(name="Benutzung:", value=prefix + "wetter (Stadt)") - embed.add_field(name="Beispiel:", value=prefix + "wetter München") - await ctx.send(embed=embed) - - @hilfe.command() - async def clear(ctx): - embed = discord.Embed(title="wetter", - description="Mit " + prefix + "clear kannst du eine beliebige Anzahl an Nachrichten aus einem Channel löschen", - color=ctx.author.color) - embed.add_field(name="Benutzung:", value=prefix + "clear (Anzahl)") - embed.add_field(name="Beispiel:", value=prefix + "clear 15") - await ctx.send(embed=embed) - - @hilfe.command() - async def benutzerinfo(ctx): - embed = discord.Embed(title="benutzerinfo", - description="Mit " + prefix + "benutzerinfo kannst du dir einige Infos über einen Nutzer anzeigen lassen", - color=ctx.author.color) - embed.add_field(name="Benutzung:", value=prefix + "benutzerinfo (Benutzer)") - embed.add_field(name="Beispiel:", value=prefix + "benutzerinfo DCGALAXY") - await ctx.send(embed=embed) - - @hilfe.command() - async def ping(ctx): - embed = discord.Embed(title="ping", - description="Mit " + prefix + "ping kannst du dir die Discord WebSocket protocol latency anzeigen lassen", - color=ctx.author.color) - embed.add_field(name="Benutzung:", value=prefix + "ping") - await ctx.send(embed=embed) - - @hilfe.command() - async def give(ctx): - embed = discord.Embed(title="ping", - description="Mit " + prefix + "give wird eine Minecraft Konsole simuliert", - color=ctx.author.color) - embed.add_field(name="Benutzung:", value=prefix + "give (item) (spieler)") - embed.add_field(name="Beispiel:", value=prefix + "give diamonds DCGALAXY") - await ctx.send(embed=embed) - - @hilfe.command() - async def lol(ctx): - embed = discord.Embed(title="lol", - description="Mit " + prefix + "lol kannst du dir eine League of Legends Stats anzeigen lassen", - color=ctx.author.color) - embed.add_field(name="Benutzung:", value=prefix + "lol (level/rang) (name)") - embed.add_field(name="Beispiel:", value=prefix + "lol rang Aftersh0ock") - await ctx.send(embed=embed) - - @hilfe.command() - async def mc(ctx): - embed = discord.Embed(title="mc", - description="Mit " + prefix + "mc (command) kannst du dir mehrere Interessante sachen zu Minecraft Anzeigen lassen", - color=ctx.author.color) - embed.add_field(name="Mehr Infos gibts es hier:", value=prefix + "mc ") - await ctx.send(embed=embed) - - @hilfe.command() - async def osu(ctx): - embed = discord.Embed(title="osu", - description="Mit " + prefix + "osu kannst du dir Osu Stats zu einem Spieler Anzeigen lassen", - color=ctx.author.color) - embed.add_field(name="Benutzung:", value=prefix + "osu (name)") - embed.add_field(name="Beispiel:", value=prefix + "osu Aftersh0ock") - await ctx.send(embed=embed) - - @hilfe.command() - async def earth2(ctx): - embed = discord.Embed(title="earth2", - description="Mit " + prefix + "earth2 kannst du dir Earth2 Stats zu Deutschland Anzeigen lassen", - color=ctx.author.color) - embed.add_field(name="Benutzung:", value=prefix + "earth2") - await ctx.send(embed=embed) - - @hilfe.command() - async def anime(ctx): - embed = discord.Embed(title="anime", - description="Sende ein Bild und als Beschreibung " + prefix + "anime und es sagt dir welcher anime es ist", - color=ctx.author.color) - embed.add_field(name="Benutzung:", value="Bild mit Kommentar" + prefix + "anime") - await ctx.send(embed=embed) - - -hilfe() - - -def give(): - @client.group(invoke_without_command=True) - async def give(ctx): - embed = discord.Embed(title="Minecraft Konsole", - description="gieb das Item und dann den Discord Namen ein".format(), - colour=ctx.author.color) - embed.set_thumbnail( - url="https://static.wikia.nocookie.net/minecraft/images/f/fe/GrassNew.png/revision/latest/top-crop/width/300/height/300?cb=20190903234415") - await ctx.send(embed=embed) - - @give.command() - async def diamonds(ctx, member: discord.Member): - randomnum = random.randint(0, 64) - embed = discord.Embed(title="Minecraft Konsole", - description="`/give {0} minecraft:diamonds {1}`".format(member.name, randomnum), - colour=ctx.author.color) - embed.set_thumbnail(url="https://freepngimg.com/thumb/minecraft/11-2-minecraft-diamond-png.png") - await ctx.send(embed=embed) - - @give.command() - async def schwert(ctx, member: discord.Member): - randomnum = random.randint(0, 64) - embed = discord.Embed(title="Minecraft Konsole", - description="`/give {0} minecraft:diamond_sword {1}`".format(member.name, randomnum), - colour=ctx.author.color) - embed.set_thumbnail(url="https://assets.stickpng.com/images/580b57fcd9996e24bc43c301.png") - await ctx.send(embed=embed) - - @give.command() - async def opgoldapfel(ctx, member: discord.Member): - randomnum = random.randint(0, 64) - embed = discord.Embed(title="Minecraft Konsole", - description="`/give {0} enchanted_golden_apple {1}`".format(member.name, randomnum), - colour=ctx.author.color) - embed.set_thumbnail( - url="https://static.wikia.nocookie.net/hypixel-skyblock/images/4/4d/Enchanted_Golden_Apple.gif/revision" - "/latest/smart/width/200/height/200?cb=20200619230630") - await ctx.send(embed=embed) - - -give() - """ ############################################################################################################################################################## Ole rewrite paradise @@ -566,7 +130,7 @@ async def wrapper(self, *args, **kwargs): if ctx.author.id == info.owner.id: return await func(self, *args, **kwargs) else: - await ctx.send("Error, only the bot owner can use this command!") + await ctx.channel.send("Error, only the bot owner can use this command!") return wrapper @@ -601,7 +165,7 @@ async def load_cog(ctx, cogName): await ctx.channel.send(f"Fehler, entweder ist die erweiterung schon geladen, oder sie wurde nicht gefunden.") -with open('config.json', 'r') as f: +with open('config/config.json', 'r') as f: json_stuff = json.load(f) token = json_stuff["token"] @@ -610,8 +174,7 @@ async def load_cog(ctx, cogName): if filename.endswith(".py"): client.load_extension(f"cogs.{filename[:-3]}") -# assign constant variables -constants.assignVariables() + # run bot client.run(token) diff --git a/cogs/anime.py b/cogs/anime.py new file mode 100644 index 0000000..9ed46f7 --- /dev/null +++ b/cogs/anime.py @@ -0,0 +1,52 @@ +from discord.ext import commands +import discord +import requests +import urllib.parse + + +class Anime(commands.Cog): + def __init__(self, client): + self.client = client + + @commands.command(name="anime") + async def anime_command(self, ctx): + base_url = "https://trace.moe/api/search?url=" + attachment = ctx.message.attachments[0] + attachementurl = attachment.url + url = base_url + attachementurl + response = requests.post(url).json()["docs"][0] + genauigkeit = response["similarity"] + hentai = response["is_adult"] + titel = response["title_english"] + nativetitel = response["title_native"] + anilist = response["anilist_id"] + filename = response["filename"] + at = response["at"] + tokenthumb = response["tokenthumb"] + # Coming Soon + filenameencoded = urllib.parse.quote(filename) + imgrequest = "https://media.trace.moe/image/" + str(anilist) + "/" + filenameencoded + "?t=" + str( + at) + "&token=" + tokenthumb + "&size=m" + ### + if titel is not None: + embed = discord.Embed(title=f"{titel}") + else: + embed = discord.Embed(title=f"{nativetitel}") + anilisturl = "https://anilist.co/anime/" + str(anilist) + embed.set_author(name="Anilist Link", url=anilisturl) + embed.add_field(name="Genauigkeit", value=f"{round(genauigkeit * 100, 2)}%") + if hentai is False: + embed.add_field(name="Hentai?", value="Nope :(") + else: + embed.add_field(name="Hentai?", value="Yess Sir") + if titel is not None: + embed.add_field(name="Titel in Orginalsprache", value=f"{nativetitel}") + else: + pass + embed.set_image(url=str(imgrequest)) + await ctx.send(embed=embed) + return + + +def setup(client): + client.add_cog(Anime(client)) diff --git a/cogs/commands.py b/cogs/commands.py new file mode 100644 index 0000000..7491951 --- /dev/null +++ b/cogs/commands.py @@ -0,0 +1,63 @@ +from discord.ext import commands +import discord +from lib import constants + + +class Commands(commands.Cog): + def __init__(self, client): + self.client = client + + def ist_gepinnt(self, message): + return not message.pinned + + @commands.command(name="ping") + async def ping_command(self, ctx): + await ctx.channel.send("Der Ping beträgt derzeit " f"{round(self.client.latency * 1000)}ms") + + @commands.command(name="version") + async def version(self, ctx): + await ctx.channel.send( + "Der Bot läuft derzeit auf Release " + str(constants.VERSION) + " und geht auch dank discord.py Version {}".format( + discord.__version__)) + + @commands.command(name="einladen") + async def einladen(self, ctx): + embed = discord.Embed() + embed.set_author(name="Klicke hier zum einladen", + url=discord.utils.oauth_url(self.client.user.id, permissions=discord.Permissions(8), guild=ctx.guild)) + await ctx.channel.send(embed=embed) + + @commands.command(name="hosten") + async def hosten_command(self, ctx): + embed = discord.Embed() + embed.set_author(name="Klicke hier um ein Tutorial zum Selber hosten zu bekommen", + url='https://github.com/antonstech/antonstechbot/wiki/Installation') + await ctx.channel.send(embed=embed) + + @commands.command(name="code") + async def code_command(self, ctx): + embed = discord.Embed() + embed.set_author(name="Hier findest du den ganzen Code vom Bot", + url='https://github.com/antonstech/antonstechbot') + await ctx.channel.send(embed=embed) + + @commands.command(name="nudes") + async def nudes_command(self, ctx): + if ctx.channel.is_nsfw(): + embed = discord.Embed(title="Nudes") + embed.set_image( + url="https://www.nydailynews.com/resizer/OYta-jTp2D6Xt_Wj_o6zEUqWttE=/415x562/top/arc-anglerfish-arc2-prod-tronc.s3.amazonaws.com/public/7Y53KJVE7FGLZZPD44LTN4QB5I.jpg") + await ctx.channel.send(embed=embed) + else: + await ctx.channel.send("Der Channel ist nicht nsfw") + + @commands.command(name="clear") + async def clear_command(self, ctx, amount=5): + try: + await ctx.channel.purge(limit=amount + 1, check=self.ist_gepinnt) + except commands.MissingPermissions: + await ctx.channel.send("Du hast keine Berechtigung dazu!") + + +def setup(client): + client.add_cog(Commands(client)) diff --git a/cogs/corona.py b/cogs/corona.py index b974c79..c04a32c 100644 --- a/cogs/corona.py +++ b/cogs/corona.py @@ -16,13 +16,13 @@ async def corona_command(self, ctx, option=None): response = requests.get(url).json() g_url = "https://api.corona-zahlen.org/vaccinations" geimpft = requests.get(g_url) - y = geimpft.json() + data = geimpft.json() channel = ctx.message.channel async with channel.typing(): insgesamt = response["cases"] todegesamt = response["deaths"] inzidenz = response["weekIncidence"] - data = y["data"] + data = data["data"] jetzgeimpft = data["quote"] infor = response["r"] rwert = infor["value"] @@ -39,14 +39,37 @@ async def corona_command(self, ctx, option=None): embed.add_field(name="Inzidenz", value=f"{round(inzidenz, 2)}") embed.add_field(name="Geimpft", value=f"{round(jetzgeimpft, 2) * 100}%") embed.add_field(name="R-Wert", value=f"{rwert}") - embed.set_footer(text="Mit " + constants.prefix + "corona geimpft gibts mehr zur Impfung") + embed.set_footer(text="Mit " + constants.bot_prefix + "corona geimpft gibts mehr zur Impfung") await ctx.send(embed=embed) embed = discord.Embed(title="Aktuelle Corona Map für Deutschland", color=ctx.author.color, timestamp=ctx.message.created_at) embed.set_image(url="https://api.corona-zahlen.org/map/districts") - embed.set_footer(text="Mit " + constants.prefix + "corona geimpft gibts mehr zur Impfung") + embed.set_footer(text="Mit " + constants.bot_prefix + "corona geimpft gibts mehr zur Impfung") await ctx.send(embed=embed) + elif option == "geimpft": + url = "https://api.corona-zahlen.org/vaccinations" + response = requests.get(url).json() + channel = ctx.message.channel + async with channel.typing(): + data = response["data"] + jetztgeimpft = data["quote"] + gesamt = data["vaccinated"] + second = data["secondVaccination"] + zweite_imfung = second["vaccinated"] + embed = discord.Embed(title="Impfen lassen", url="https://antonstech.de/impfung.html", + color=ctx.author.color) + await ctx.send(embed=embed) + embed = discord.Embed(title="Statistiken zur Impfung in Deutschland", + color=ctx.author.color) + embed.add_field(name="Prozent der Bevölkerung", value=f"{round(jetztgeimpft, 2) * 100}%") + embed.add_field(name="Anzahl der Geimpften", value=f"{gesamt} Personen", inline=False) + embed.add_field(name="Zweite Impfung haben bereits erhalten", value=f"{zweite_imfung} Personen") + await ctx.send(embed=embed) + + return + + def setup(client): client.add_cog(Corona(client)) diff --git a/cogs/earth2.py b/cogs/earth2.py new file mode 100644 index 0000000..6364c61 --- /dev/null +++ b/cogs/earth2.py @@ -0,0 +1,27 @@ +from discord.ext import commands +import discord +import requests + + +class Earth2(commands.Cog): + def __init__(self, client): + self.client = client + + @commands.command(name="earth2") + async def earth2_command(self, ctx): + url = "https://earth2stats.net/api/get_countries/199" + response = requests.get(url).json() + land = response["name"] + wert = response["marketplace_tile_value"] + verkauft = response["total_sold_tiles"] + embed = discord.Embed(title="Earth2 Statistiken für " + land, url="https://earth2stats.net/country/" + land) + embed.set_thumbnail( + url="https://static-cdn.jtvnw.net/jtv_user_pictures/99783da2-3f60-4aeb-92bd-83e953c03627-profile_image-70x70.png") + embed.add_field(name="Wert eines Tiles", value=f"{wert}E$") + embed.add_field(name="Insgesamt verkauft", value=f"{verkauft} Tiles") + await ctx.send(embed=embed) + return + + +def setup(client): + client.add_cog(Earth2(client)) diff --git a/cogs/events.py b/cogs/events.py index 828e5ec..1ca1245 100644 --- a/cogs/events.py +++ b/cogs/events.py @@ -43,7 +43,7 @@ async def sql_connection_stuff(self, message): mycursor.executemany(sql, val) mydb.commit() - @commands.Cog.listener + @commands.Cog.listener() async def on_message(self, message): asyncio.ensure_future(self.sql_connection_stuff(message)) diff --git a/cogs/give.py b/cogs/give.py new file mode 100644 index 0000000..475eb97 --- /dev/null +++ b/cogs/give.py @@ -0,0 +1,49 @@ +from discord.ext import commands +import discord +import random + + +class Give(commands.Cog): + def __init__(self, client): + self.client = client + + @commands.command(name="give") + async def give_command(self, ctx, item=None, member: discord.Member=None): + randomnum = random.randint(0, 64) + if item is None: + embed = discord.Embed(title="Minecraft Konsole", + description="gieb das Item und dann den Discord Namen ein".format(), + colour=ctx.author.color) + embed.set_thumbnail( + url="https://static.wikia.nocookie.net/minecraft/images/f/fe/GrassNew.png/revision/latest/top-crop/width/300/height/300?cb=20190903234415") + await ctx.channel.send(embed=embed) + + if member is None: + await ctx.channel.send("Du musst einen discord nutzer angeben!") + + elif item == "diamonds": + embed = discord.Embed(title="Minecraft Konsole", + description="`/give {0} minecraft:diamonds {1}`".format(member.name, randomnum), + colour=ctx.author.color) + embed.set_thumbnail(url="https://freepngimg.com/thumb/minecraft/11-2-minecraft-diamond-png.png") + await ctx.channel.send(embed=embed) + + elif item == "schwert": + embed = discord.Embed(title="Minecraft Konsole", + description="`/give {0} minecraft:diamond_sword {1}`".format(member.name, randomnum), + colour=ctx.author.color) + embed.set_thumbnail(url="https://assets.stickpng.com/images/580b57fcd9996e24bc43c301.png") + await ctx.send(embed=embed) + + elif item == "opgoldapfel": + embed = discord.Embed(title="Minecraft Konsole", + description="`/give {0} enchanted_golden_apple {1}`".format(member.name, randomnum), + colour=ctx.author.color) + embed.set_thumbnail( + url="https://static.wikia.nocookie.net/hypixel-skyblock/images/4/4d/Enchanted_Golden_Apple.gif/revision" + "/latest/smart/width/200/height/200?cb=20200619230630") + await ctx.send(embed=embed) + + +def setup(client): + client.add_cog(Give(client)) diff --git a/cogs/hilfe.py b/cogs/hilfe.py new file mode 100644 index 0000000..211b180 --- /dev/null +++ b/cogs/hilfe.py @@ -0,0 +1,51 @@ +from discord.ext import commands +import discord +from lib import constants +import json + + +class Hilfe(commands.Cog): + def __init__(self, client): + self.client = client + + async def send(self, ctx, command_name, description, usage, example): + embed = discord.Embed(title=command_name, + description=description.format(constants.bot_prefix), + color=ctx.author.color) + embed.add_field(name="Benutzung:", value=usage.format(constants.bot_prefix)) + embed.add_field(name="Beispiel:", value=example.format(constants.bot_prefix)) + await ctx.channel.send(embed=embed) + + @commands.command(name="hilfe") + async def hilfe_command(self, ctx, command_name=None): + + if command_name is None: + embed = discord.Embed(title="Hilfe", + description="Benutze " + constants.bot_prefix + "hilfe (command) für mehr Informationen zu einem Command.", + color=ctx.author.color) + embed.add_field(name="Moderation:", value="clear") + embed.add_field(name="nützlich:", value="wetter, benutzerinfo , ping, anime", inline=True) + embed.add_field(name="fun", value="give, corona, earth2", inline=True) + embed.add_field(name="Game-Stats", value="lol, osu", inline=True) + embed.add_field(name="Minecraft Zeugs", value="mc", inline=True) + embed.add_field(name="Infos zum Bot", value="version, einladen, hosten, code", inline=True) + embed.set_footer(text='Bei sonstigen Fragen einfach DCGALAXY#9729 anschreiben') + await ctx.send(embed=embed) + return + + with open("lib/help.json") as f: + json_stuff = json.load(f) + + try: + base = json_stuff[command_name] + description = base["description"] + usage = base["usage"] + example = base["example"] + await self.send(ctx, command_name, description, usage, example) + + except KeyError: + pass + + +def setup(client): + client.add_cog(Hilfe(client)) diff --git a/cogs/ip.py b/cogs/ip.py new file mode 100644 index 0000000..495b6d8 --- /dev/null +++ b/cogs/ip.py @@ -0,0 +1,43 @@ +from discord.ext import commands +import discord +from lib import constants +import requests + + +class Ip(commands.Cog): + def __init__(self, client): + self.client = client + self.ipdata = constants.ipdata_token + self.base_url = constants.ipdata_url + + @commands.command(name="ip") + async def ip_command(self, ctx, ip): + apiurl = "?api-key=" + self.ipdata + resulturl = self.base_url + ip + apiurl + response = requests.get(resulturl) + x = response.json() + city = x["city"] + country = x["country_name"] + flag = x["flag"] + y = x["asn"] + asn = y["name"] + asntype = y["type"] + postleitzahl = x["postal"] + kontinent = x["continent_name"] + embed = discord.Embed(title="IP Informationen zu " + ip) + embed.set_thumbnail(url=flag) + embed.add_field(name="Land", value=f"{country}") + embed.add_field(name="Stadt", value=f"{city}") + embed.add_field(name="Kontinent", value=f"{kontinent}") + if postleitzahl is None: + pass + else: + embed.add_field(name="Postleitzahl", value=f"{postleitzahl}") + embed.add_field(name="Internetanbieter", value=f"{asn}") + embed.add_field(name="Anbiter-Type", value=f"{asntype}") + await ctx.send(embed=embed) + return + + +def setup(client): + client.add_cog(Ip(client)) diff --git a/cogs/lol.py b/cogs/lol.py index 8f71e68..f6cb12d 100644 --- a/cogs/lol.py +++ b/cogs/lol.py @@ -1,6 +1,6 @@ from discord.ext import commands import discord -import json +from lib import constants import requests from lib import constants from riotwatcher import LolWatcher @@ -9,14 +9,8 @@ class Lol(commands.Cog): def __init__(self, client): self.client = client - with open('./config.json', 'r') as f: - json_stuff = json.load(f) - self.api_key = json_stuff["riotapi"] - self.base_url = "https://euw1.api.riotgames.com/lol/" - - @commands.Cog.listener() - async def on_ready(self): - print("lolcommand hat geladen") + self.api_key = constants.lol_token + self.base_url = constants.lol_url @commands.command(name="lol") async def lol_command(self, ctx, option=None, username=None): diff --git a/cogs/osu.py b/cogs/osu.py new file mode 100644 index 0000000..bd0526d --- /dev/null +++ b/cogs/osu.py @@ -0,0 +1,46 @@ +from discord.ext import commands +import discord +from lib import constants +import requests + + +class Osu(commands.Cog): + def __init__(self, client): + self.client = client + self.osuapi = constants.osu_token + self.url = constants.osu_url + + @commands.command(name="osu") + async def osu_command(self, ctx, name): + try: + spielerstats = self.url + name + "&k=" + self.osuapi + response = requests.get(spielerstats).json()[0] + userid = response["user_id"] + playedgames = response["playcount"] + level = response["level"] + levelgerundet = (int(float(level))) + spielzeit_sekunden = response["total_seconds_played"] + spielzeit_stunden = int(spielzeit_sekunden) / 3600 + genauigkeit = response["accuracy"] + genauigkeit_int = (int(float(genauigkeit))) + globalrank = response["pp_rank"] + localrank = response["pp_country_rank"] + land = response["country"] + embed = discord.Embed(title="Osu Stats für " + name) + embed.set_thumbnail(url="http://s.ppy.sh/a/" + userid) + embed.add_field(name="Gespielte Spiele", value=f"{playedgames}") + embed.add_field(name="Level", value=f"{levelgerundet}") + embed.add_field(name="Spielzeit", value=f"{(int(float(spielzeit_stunden)))} Stunden") + embed.add_field(name="Genauigkeit", value=f"{round(genauigkeit_int, 2)}%") + embed.add_field(name="Globaler Rang", value=f"{globalrank}") + embed.add_field(name="Rang in " + land, value=f"{localrank}") + await ctx.send(embed=embed) + except: + await ctx.send( + "Irgendetwas ist schief gelaufen; check ob der Name richtig geschrieben ist und falls es dann nicht geht Kontaktiere DCGALAXY#9729") + + return + + +def setup(client): + client.add_cog(Osu(client)) \ No newline at end of file diff --git a/config.json.example b/config/config.json.example similarity index 100% rename from config.json.example rename to config/config.json.example diff --git a/mysql.json.example b/config/mysql.json.example similarity index 100% rename from mysql.json.example rename to config/mysql.json.example diff --git a/lib/__init__.py b/lib/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/lib/constants.py b/lib/constants.py new file mode 100644 index 0000000..c0c5c06 --- /dev/null +++ b/lib/constants.py @@ -0,0 +1,25 @@ +import subprocess +import json + +global VERSION, bot_prefix, ipdata_token, ipdata_url, osu_token, osu_url, lol_token, lol_url, bot_token + + +def assignVariables(): + global VERSION, bot_prefix, ipdata_token, ipdata_url, osu_token, osu_url, lol_token, lol_url, bot_token + VERSION = subprocess.check_output(["git", "describe", "--tags", "--always"]).decode('ascii').strip() + + with open('config/config.json', 'r') as f: + json_stuff = json.load(f) + + bot_prefix = json_stuff["prefix"] + + bot_token = json_stuff["token"] + + ipdata_token = json_stuff["ipdata"] + ipdata_url = "https://api.ipdata.co/" + + osu_token = json_stuff["osuapi"] + osu_url = "https://osu.ppy.sh/api/get_user?u=" + + lol_token = json_stuff["riotapi"] + lol_url = "https://euw1.api.riotgames.com/lol/" diff --git a/lib/help.json b/lib/help.json new file mode 100644 index 0000000..30fd130 --- /dev/null +++ b/lib/help.json @@ -0,0 +1,61 @@ +{ + "wetter": { + "description": "Mit {0}wetter kannst du dir das Wetter so wie einige Infos dazu anzeigen lassen", + "usage": "{0}wetter Stadt", + "example": "{0}wetter München" + }, + + "clear": { + "description": "Mit {0}clear kannst du eine beliebige Anzahl an Nachrichten aus einem Channel löschen", + "usage": "{0}clear (Anzahl)", + "example": "{0}clear 5" + }, + + "benutzerinfo":{ + "description": "Mit {0}benutzerinfo kannst du dir einige Infos über einen Nutzer anzeigen lassen", + "usage": "{0}benutzerinfo (Benutzer)", + "example": "{0}benutzerinfo DCGALAXY" + }, + + "ping": { + "description": "Mit {0}ping kannst du dir die Discord WebSocket protocol latency anzeigen lassen", + "usage": "{0}ping", + "example": "{0}ping" + }, + + "give": { + "description": "Mit {0}give wird eine Minecraft Konsole simuliert", + "usage": "{0}give (item) (spieler)", + "example": "{0}give diamonds DCGALAXY" + }, + + "lol": { + "description": "Mit {0}lol kannst du dir eine League of Legends Stats anzeigen lassen", + "usage": "{0}lol (level/rang) (name)", + "example": "{0}lol rang Aftersh0ock" + }, + + "mc": { + "description": "Mit {0}mc (command) kannst du dir mehrere Interessante sachen zu Minecraft Anzeigen lassen", + "usage": "Mehr info gibt hier: {0}mc", + "example": "Mehr info gibt hier: {0}mc" + }, + + "osu": { + "description": "Mit {0}osu kannst du dir Osu Stats zu einem Spieler Anzeigen lassen", + "usage": "{0}osu (name)", + "example": "{0}osu Aftersh0ock" + }, + + "earth2": { + "description": "Mit {0}earth2 kannst du dir Earth2 Stats zu Deutschland Anzeigen lassen", + "usage": "{0}earth2", + "example": "{0}earth2" + }, + + "anime": { + "description": "Sende ein Bild und als Beschreibung {0}anime und es sagt dir welcher anime es ist", + "usage": "Bild mit Kommentar {0}anime", + "example": "https://i.imgur.com/P43xKu4.png" + } +} \ No newline at end of file diff --git a/lib/utils.py b/lib/utils.py new file mode 100644 index 0000000..44607c2 --- /dev/null +++ b/lib/utils.py @@ -0,0 +1,16 @@ +import inspect + + +def get_variable(name): + stack = inspect.stack() + try: + for frames in stack: + try: + frame = frames[0] + current_locals = frame.f_locals + if name in current_locals: + return current_locals[name] + finally: + del frame + finally: + del stack diff --git a/start.py b/start.py index 0d45068..3996102 100644 --- a/start.py +++ b/start.py @@ -21,7 +21,7 @@ def browser(): def tokenchecker(): # Riot - with open('./config.json', 'r') as f: + with open('config/config.json', 'r') as f: json_stuff = json.load(f) riotapi = json_stuff["riotapi"] base_riot_url = "https://euw1.api.riotgames.com/lol/summoner/v4/summoners/by-name/DCGALAXY?api_key=" @@ -32,7 +32,7 @@ def tokenchecker(): else: print(Fore.RED + "Riot Games API Key ❌") # Osu - with open('./config.json', 'r') as f: + with open('config/config.json', 'r') as f: json_stuff = json.load(f) osuapi = json_stuff["osuapi"] base_osu_url = "https://osu.ppy.sh/api/get_user_best?u=Aftersh0ock&k=" @@ -43,7 +43,7 @@ def tokenchecker(): else: print(Fore.RED + "Osu API Key ❌") # Discord - with open('config.json', 'r') as f: + with open('config/config.json', 'r') as f: json_stuff = json.load(f) token = json_stuff["token"] headers = { @@ -55,7 +55,7 @@ def tokenchecker(): else: print(Fore.RED + "Discord Token ❌") # ipdata - with open('./config.json', 'r') as f: + with open('config/config.json', 'r') as f: json_stuff = json.load(f) ipdata = json_stuff["ipdata"] baseipurl = "https://api.ipdata.co/8.8.8.8" @@ -115,7 +115,7 @@ def tokens(): config = {'token': input("Dein Bot Token: "), 'prefix': input("Dein Bot Prefix: "), "riotapi": input("Dein Riot Games Api Token: "), "osuapi": input("Dein Osu Api Token: "), "ipdata": input("Dein ipdata.co Token: ")} - with open('config.json', 'w+') as file: + with open('config/config.json', 'w+') as file: json.dump(config, file, indent=2) From 396a00e45223c604dfcd5413a12a462d8aad9512 Mon Sep 17 00:00:00 2001 From: DestinyofYeet Date: Wed, 17 Mar 2021 10:03:07 +0100 Subject: [PATCH 3/9] fixed start and update option in start.py --- start.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/start.py b/start.py index 3996102..abcf2d2 100644 --- a/start.py +++ b/start.py @@ -1,6 +1,7 @@ from consolemenu import * from consolemenu.items import * import os +import sys import subprocess import webbrowser import time @@ -145,12 +146,26 @@ def mysqlenable(): print("https://github.com/antonstech/antonstechbot/wiki/Support") +def run_bot(): + if sys.platform == "win32": + os.system("py -3 bot.py") + else: + os.system("python3 bot.py") + + +def update_bot(): + if sys.platform == "win32": + os.system("py -3 update.py") + else: + os.system("python3 update.py") + + menu = ConsoleMenu(f"antonstechbot Version {VERSION} by antonstech", "https://git.io/antonsbot") -starten = FunctionItem("Bot starten", os.system, ["python3 bot.py"]) +starten = FunctionItem("Bot starten", run_bot) config = FunctionItem("Config bearbeiten", tokens) -updaten = FunctionItem("Bot Updaten", os.system, ["python3 update.py"]) +updaten = FunctionItem("Bot Updaten", update_bot) tokencheck = FunctionItem("Token-Checker", tokenchecker) infos = FunctionItem("Infos über den Bot&Code", browser) mysqlsetup = FunctionItem("MySQL Setup", mysqlsetup) From 62664d88c69405f5aeeeb22ad95402270cc0a9da Mon Sep 17 00:00:00 2001 From: DestinyofYeet Date: Wed, 17 Mar 2021 10:30:25 +0100 Subject: [PATCH 4/9] hopefully fixed unresolved reference stuff for constants.py --- lib/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 lib/__init__.py diff --git a/lib/__init__.py b/lib/__init__.py deleted file mode 100644 index e69de29..0000000 From f255152d8a60fc9757a84d7ee1b3177ec39bbdb1 Mon Sep 17 00:00:00 2001 From: DestinyofYeet Date: Wed, 17 Mar 2021 10:42:06 +0100 Subject: [PATCH 5/9] resolved conflict with pip 'lib' library --- botlibrary/__init__.py | 0 {lib => botlibrary}/constants.py | 0 {lib => botlibrary}/help.json | 0 {lib => botlibrary}/utils.py | 0 4 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 botlibrary/__init__.py rename {lib => botlibrary}/constants.py (100%) rename {lib => botlibrary}/help.json (100%) rename {lib => botlibrary}/utils.py (100%) diff --git a/botlibrary/__init__.py b/botlibrary/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/lib/constants.py b/botlibrary/constants.py similarity index 100% rename from lib/constants.py rename to botlibrary/constants.py diff --git a/lib/help.json b/botlibrary/help.json similarity index 100% rename from lib/help.json rename to botlibrary/help.json diff --git a/lib/utils.py b/botlibrary/utils.py similarity index 100% rename from lib/utils.py rename to botlibrary/utils.py From 2731e0e5054df1e9c8e9300cafc1b6ba83b74619 Mon Sep 17 00:00:00 2001 From: DestinyofYeet Date: Wed, 17 Mar 2021 10:43:34 +0100 Subject: [PATCH 6/9] resolved conflict with pip 'lib' library --- bot.py | 4 ++-- cogs/commands.py | 2 +- cogs/corona.py | 2 +- cogs/hilfe.py | 4 ++-- cogs/ip.py | 2 +- cogs/lol.py | 4 ++-- cogs/osu.py | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/bot.py b/bot.py index 615b201..011aaa5 100644 --- a/bot.py +++ b/bot.py @@ -8,8 +8,8 @@ from discord.ext import commands import os -from lib.utils import get_variable -from lib import constants +from botlibrary.utils import get_variable +from botlibrary import constants # Wichs Codierung # ä=ü diff --git a/cogs/commands.py b/cogs/commands.py index 7491951..6488c8a 100644 --- a/cogs/commands.py +++ b/cogs/commands.py @@ -1,6 +1,6 @@ from discord.ext import commands import discord -from lib import constants +from botlibrary import constants class Commands(commands.Cog): diff --git a/cogs/corona.py b/cogs/corona.py index c04a32c..b860bd3 100644 --- a/cogs/corona.py +++ b/cogs/corona.py @@ -1,7 +1,7 @@ from discord.ext import commands import discord import requests -from lib import constants +from botlibrary import constants class Corona(commands.Cog): diff --git a/cogs/hilfe.py b/cogs/hilfe.py index 211b180..5ebe22b 100644 --- a/cogs/hilfe.py +++ b/cogs/hilfe.py @@ -1,6 +1,6 @@ from discord.ext import commands import discord -from lib import constants +from botlibrary import constants import json @@ -33,7 +33,7 @@ async def hilfe_command(self, ctx, command_name=None): await ctx.send(embed=embed) return - with open("lib/help.json") as f: + with open("botlibrary/help.json") as f: json_stuff = json.load(f) try: diff --git a/cogs/ip.py b/cogs/ip.py index 495b6d8..ec13343 100644 --- a/cogs/ip.py +++ b/cogs/ip.py @@ -1,6 +1,6 @@ from discord.ext import commands import discord -from lib import constants +from botlibrary import constants import requests diff --git a/cogs/lol.py b/cogs/lol.py index f6cb12d..12110de 100644 --- a/cogs/lol.py +++ b/cogs/lol.py @@ -1,8 +1,8 @@ from discord.ext import commands import discord -from lib import constants +from botlibrary import constants import requests -from lib import constants +from botlibrary import constants from riotwatcher import LolWatcher diff --git a/cogs/osu.py b/cogs/osu.py index bd0526d..b935ba3 100644 --- a/cogs/osu.py +++ b/cogs/osu.py @@ -1,6 +1,6 @@ from discord.ext import commands import discord -from lib import constants +from botlibrary import constants import requests From bba930694d7e44d9da5115a3fb3897b3634aebaa Mon Sep 17 00:00:00 2001 From: DestinyofYeet Date: Wed, 17 Mar 2021 10:49:05 +0100 Subject: [PATCH 7/9] fixed path stuff --- start.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/start.py b/start.py index abcf2d2..eeff077 100644 --- a/start.py +++ b/start.py @@ -80,9 +80,9 @@ def mysqlsetup(): config = {"enable": True, "host": input("Host: "), "user": input("Benutzername: "), "passwort": input("Dein Passwort: "), "datenbank": input("Datenbank: "), "tablename": input("Name der Tablle: "), "port": input("Port: ")} - with open("mysql.json", "w+") as file: + with open("config/mysql.json", "w+") as file: json.dump(config, file, indent=2) - with open('mysql.json', 'r') as f: + with open('config/mysql.json', 'r') as f: json_stuff = json.load(f) host = json_stuff["host"] user = json_stuff["user"] @@ -121,12 +121,12 @@ def tokens(): def mysqldisable(): - if os.path.exists("mysql.json"): - os.rename("mysql.json", "disabled_mysql.json") + if os.path.exists("config/mysql.json"): + os.rename("config/mysql.json", "config/disabled_mysql.json") print("MySQL ist nun DEAKTIVIEREN!") print("Du musst den Bot 1x neustarten damit die Änderung wirksam wird!") else: - if os.path.exists("disabled_mysql.json"): + if os.path.exists("config/disabled_mysql.json"): print("MySQL ist bereits deaktiviert") else: print("Iwas ist falsch gelaufen. Hier gibt es Hilfe:") @@ -134,12 +134,12 @@ def mysqldisable(): def mysqlenable(): - if os.path.exists("disabled_mysql.json"): - os.rename("disabled_mysql.json", "mysql.json") + if os.path.exists("config/disabled_mysql.json"): + os.rename("config/disabled_mysql.json", "config/mysql.json") print("MySQL ist nun AKTIVIERT!") print("Du musst den Bot 1x neustarten damit die Änderung wirksam wird!") else: - if os.path.exists("mysql.json"): + if os.path.exists("config/mysql.json"): print("MySQL ist bereits aktiviert") else: print("Iwas ist falsch gelaufen. Hier gibt es Hilfe:") From 1b06ca4cf3b5ba6b85b965b225a9418669166541 Mon Sep 17 00:00:00 2001 From: DestinyofYeet Date: Wed, 17 Mar 2021 11:03:02 +0100 Subject: [PATCH 8/9] fixed mysql.json path --- bot.py | 2 +- cogs/events.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bot.py b/bot.py index 011aaa5..f70c9d6 100644 --- a/bot.py +++ b/bot.py @@ -92,7 +92,7 @@ async def on_ready(): print("Yess der bot läuft :)".format(client)) print("Du hast derzeit Release " + str(VERSION) + " installiert") print("Du bist eingeloggt als {0.user} auf discord.py Version {1}".format(client, discord.__version__)) - if os.path.exists("mysql.json"): + if os.path.exists("config/mysql.json"): print("MySQL-Logging ist AKTIVIERT") else: print("MySQL-Logging ist DEAKTIVIERT") diff --git a/cogs/events.py b/cogs/events.py index 1ca1245..797fdef 100644 --- a/cogs/events.py +++ b/cogs/events.py @@ -10,7 +10,7 @@ class Events(commands.Cog): def __init__(self, client): self.client = client self.use_mysql = False - if os.path.exists("mysql.json"): + if os.path.exists("config/mysql.json"): with open('mysql.json', 'r') as f: json_stuff = json.load(f) self.host = json_stuff["host"] From b01372431a3a2b51fb83180cf8caa1a168e294ad Mon Sep 17 00:00:00 2001 From: DestinyofYeet Date: Wed, 17 Mar 2021 11:14:39 +0100 Subject: [PATCH 9/9] fixed mysql.json path in events.py --- botlibrary/__pycache__/constants.cpython-38.pyc | Bin 0 -> 774 bytes botlibrary/__pycache__/utils.cpython-38.pyc | Bin 0 -> 419 bytes cogs/events.py | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 botlibrary/__pycache__/constants.cpython-38.pyc create mode 100644 botlibrary/__pycache__/utils.cpython-38.pyc diff --git a/botlibrary/__pycache__/constants.cpython-38.pyc b/botlibrary/__pycache__/constants.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..44c8cd4290650d6dac0446a42a25d5cf70e43afd GIT binary patch literal 774 zcmYjPJ8#=C5GG~4tk|*9Awb$p?c~7{I&=y8egR!vBtg@_FyPW6EwhnDfuxYwNTzo0 zU$Dn6{Xtwi6#WaGdbDgH6z;q4J|4+Cil5r;2*LRC>*UK>1EJqGxH}vOUV^D30E#Hi z(XjS-h^a#x-_g*a_zd;jzmS0jsm0x}tD9hNz?25iXocx!9d$EzjaLr!02^yWTu43@?( zC7beV<7sip3gh#V5>1u|Gp$Q?oFt^=ajnIvNQ^I31=8~2ZXV*eEElnw+0-OsdR!?c zUsTUbAi2;s`Oz+!RacK=yQ7`S$ebzIbe`lQPkLPwscKS6kus%BE1j|Qax5xcR@(TK zrGhf!DJ^+vg7bH$XCFQej4Mj0+1>Qw=7LZYO@tnATWVTfx7Dg!sH0)DjVhU&CN!{> z14}m=6tvSU1+C{8JT;L$X{>ZLo&H4f5dQkV{>Aa=RiQ=kTIl!udPFQ&nx!*1eU$Ub z2rgV{kX2kROou4Nv*MgcP9`~1fqgy)0LVFVS~zk-`(bx$@&U~B8q&UG*|lJW&B=G* WK4>Oen$asfgddjA2tDc->V literal 0 HcmV?d00001 diff --git a/botlibrary/__pycache__/utils.cpython-38.pyc b/botlibrary/__pycache__/utils.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a750d1b3e22a7c94559773af0aa68e7c215ae282 GIT binary patch literal 419 zcmYjN!AiqG5S`s5Z7jBU@L=y=a_LPFk)l<4EJzhgiPSW^)!1!PcekP?@g(>g>djx; zt0#ZKi_V539e8ivFmIUMxv1A`fbqL~cKu2KzHG4`6pJH-+D2l)h=3t5%A6M%5=QzE zxZl`;UX0WK;i0M`P7vxGNy8g?hk`6SIXQ)^{emuAIc1~?g_ApXv~Y9C-DyR(b5u>Z zgpURVV)IrXc@LhQ0o*rAMF#j1+)R7YE)5)0O;R=Iu{NI4Q9L#NWF)dU5-RYFn?^G( z9W2C5EMpi4$<`ht{aHXAY>e_bhd}YmGLrVf@2c#ukFN?Z1@u G`pzG$E?OA? literal 0 HcmV?d00001 diff --git a/cogs/events.py b/cogs/events.py index 797fdef..c0573c9 100644 --- a/cogs/events.py +++ b/cogs/events.py @@ -11,7 +11,7 @@ def __init__(self, client): self.client = client self.use_mysql = False if os.path.exists("config/mysql.json"): - with open('mysql.json', 'r') as f: + with open('config/mysql.json', 'r') as f: json_stuff = json.load(f) self.host = json_stuff["host"] self. user = json_stuff["user"]