diff --git a/bot.py b/bot.py index e30a1a6..29a6ca8 100644 --- a/bot.py +++ b/bot.py @@ -1,5 +1,7 @@ -import discord, wikipedia +import discord, wikipedia, json from discord import Option + +from random import randrange #from private.config import token @@ -13,8 +15,6 @@ g_ids = [1261698917163077632] async def on_ready(): print(f"We've logged in as {bot.user}.") - - @bot.slash_command(guild_ids=g_ids, name = "summary", description="Returns a Wikipedia summary") async def summary(ctx, search: Option(str, description="What do you want to get summary for?", required = True), lang: Option(str, description="Language of wiki", required = False) = "en"): await ctx.channel.trigger_typing() # that bot is typing @@ -95,5 +95,44 @@ async def random(ctx, lang: Option(str, description = "Language of wiki", requir await ctx.send(f"https://{lang}.wikipedia.org/wiki/{ran_article}") +@bot.slash_command(guild_ids=g_ids, name = "addfact", description="Adds fun fact into pool") +async def new_joke(ctx, fact: Option(str, description = "Text of the fun fact", required = True)): + await ctx.channel.trigger_typing() + + with open("funfacts.json", "r") as f: + jokes = json.load(f) + + new = {} + new["author"] = str(ctx.author.id) + new["rating"] = 0 + new["txt"] = str(fact) + + jokes["funfacts"].append(new) + + try: + await ctx.respond(f"~ moc děkuju Senpai ~ UwU") + except: + await ctx.send(f"~ moc děkuju Senpai ~ UwU") + + with open("funfacts.json", "w") as f: + json.dump(jokes, f) + return True + + +@bot.slash_command(guild_ids=g_ids, name = "random_fact", description="Reads facts from the pool") +async def random_joke(ctx): + await ctx.channel.trigger_typing() + + with open("funfacts.json", "r") as f: + jokes = json.load(f) + + ran = randrange(len(jokes["funfacts"])) + print(jokes["funfacts"][ran]) + + #try: + # await ctx.respond(f"~ moc děkuju Senpai ~ UwU") + #except: + # await ctx.send(f"~ moc děkuju Senpai ~ UwU") + bot.run("MTMyNTk1Mzg4OTcyNzQxNDM0Mw.G2Tgo0.2OhbgaVYhys0BhxJMVgGDnG0W5qvxH-soJML3M") diff --git a/funfacts.json b/funfacts.json new file mode 100644 index 0000000..74db035 --- /dev/null +++ b/funfacts.json @@ -0,0 +1 @@ +{"funfacts": [{"author": "412092791733354521", "rating": 0, "txt": "a"}, {"author": "412092791733354521", "rating": 0, "txt": "b"}, {"author": "412092791733354521", "rating": 0, "txt": "c"}]} \ No newline at end of file