proof of concept add jokes and restore random one

This commit is contained in:
ggodot 2025-02-03 23:42:37 +01:00
parent 49cc0f4131
commit 16721f80ed
2 changed files with 43 additions and 3 deletions

45
bot.py
View File

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

1
funfacts.json Normal file
View File

@ -0,0 +1 @@
{"funfacts": [{"author": "412092791733354521", "rating": 0, "txt": "a"}, {"author": "412092791733354521", "rating": 0, "txt": "b"}, {"author": "412092791733354521", "rating": 0, "txt": "c"}]}