proof of concept add jokes and restore random one
This commit is contained in:
parent
49cc0f4131
commit
16721f80ed
45
bot.py
45
bot.py
@ -1,5 +1,7 @@
|
|||||||
import discord, wikipedia
|
import discord, wikipedia, json
|
||||||
from discord import Option
|
from discord import Option
|
||||||
|
|
||||||
|
from random import randrange
|
||||||
#from private.config import token
|
#from private.config import token
|
||||||
|
|
||||||
|
|
||||||
@ -13,8 +15,6 @@ g_ids = [1261698917163077632]
|
|||||||
async def on_ready():
|
async def on_ready():
|
||||||
print(f"We've logged in as {bot.user}.")
|
print(f"We've logged in as {bot.user}.")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@bot.slash_command(guild_ids=g_ids, name = "summary", description="Returns a Wikipedia summary")
|
@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"):
|
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
|
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}")
|
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")
|
bot.run("MTMyNTk1Mzg4OTcyNzQxNDM0Mw.G2Tgo0.2OhbgaVYhys0BhxJMVgGDnG0W5qvxH-soJML3M")
|
||||||
|
|||||||
1
funfacts.json
Normal file
1
funfacts.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"funfacts": [{"author": "412092791733354521", "rating": 0, "txt": "a"}, {"author": "412092791733354521", "rating": 0, "txt": "b"}, {"author": "412092791733354521", "rating": 0, "txt": "c"}]}
|
||||||
Loading…
x
Reference in New Issue
Block a user