funfact upvotes
This commit is contained in:
parent
16721f80ed
commit
a2f2b6a055
46
bot.py
46
bot.py
@ -1,5 +1,6 @@
|
|||||||
import discord, wikipedia, json
|
import discord, wikipedia, json
|
||||||
from discord import Option
|
from discord import Option
|
||||||
|
import asyncio
|
||||||
|
|
||||||
from random import randrange
|
from random import randrange
|
||||||
#from private.config import token
|
#from private.config import token
|
||||||
@ -104,7 +105,9 @@ async def new_joke(ctx, fact: Option(str, description = "Text of the fun fact",
|
|||||||
|
|
||||||
new = {}
|
new = {}
|
||||||
new["author"] = str(ctx.author.id)
|
new["author"] = str(ctx.author.id)
|
||||||
new["rating"] = 0
|
new["upvotes"] = 0
|
||||||
|
new["downvotes"] = 0
|
||||||
|
new["visited"] = 0
|
||||||
new["txt"] = str(fact)
|
new["txt"] = str(fact)
|
||||||
|
|
||||||
jokes["funfacts"].append(new)
|
jokes["funfacts"].append(new)
|
||||||
@ -119,20 +122,47 @@ async def new_joke(ctx, fact: Option(str, description = "Text of the fun fact",
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@bot.slash_command(guild_ids=g_ids, name = "random_fact", description="Reads facts from the pool")
|
@bot.slash_command(guild_ids=g_ids, name = "funfact", description="Reads facts from the pool")
|
||||||
async def random_joke(ctx):
|
async def funfact(ctx):
|
||||||
await ctx.channel.trigger_typing()
|
await ctx.channel.trigger_typing()
|
||||||
|
|
||||||
with open("funfacts.json", "r") as f:
|
with open("funfacts.json", "r") as f:
|
||||||
jokes = json.load(f)
|
jokes = json.load(f)
|
||||||
|
|
||||||
ran = randrange(len(jokes["funfacts"]))
|
ran = randrange(len(jokes["funfacts"]))
|
||||||
print(jokes["funfacts"][ran])
|
|
||||||
|
|
||||||
#try:
|
msg = await ctx.send(f"Jednou jsem slyšela že: {jokes["funfacts"][ran]["txt"]}")
|
||||||
# await ctx.respond(f"~ moc děkuju Senpai ~ UwU")
|
|
||||||
#except:
|
jokes["funfacts"][ran]["visited"] =+ 1
|
||||||
# await ctx.send(f"~ moc děkuju Senpai ~ UwU")
|
|
||||||
|
love = ""
|
||||||
|
change = 0
|
||||||
|
|
||||||
|
await msg.add_reaction("\U0001F44D")
|
||||||
|
await msg.add_reaction("\U0001F44E")
|
||||||
|
|
||||||
|
await asyncio.sleep(60)
|
||||||
|
|
||||||
|
msg_cached = discord.utils.get(bot.cached_messages, id=msg.id)
|
||||||
|
for emo in msg_cached.reactions:
|
||||||
|
if emo.emoji == "👍":
|
||||||
|
jokes["funfacts"][ran]["upvotes"]+= emo.count - 1
|
||||||
|
change+= 1
|
||||||
|
elif emo.emoji == "👎":
|
||||||
|
jokes["funfacts"][ran]["downvotes"]+= emo.count - 1
|
||||||
|
change+= 1
|
||||||
|
elif emo.emoji == "🫀":
|
||||||
|
love = ', já Vás mám taky ráda 🫀'
|
||||||
|
|
||||||
|
if change != 0:
|
||||||
|
await ctx.send(f"Děkuju za ohodnoceni. {jokes["funfacts"][ran]["upvotes"]} říká že dobrý a {jokes["funfacts"][ran]["downvotes"]} že ne{love}. ")
|
||||||
|
else:
|
||||||
|
await ctx.send(f"Hlasovaní skončilo. Můžete zkusit další {love}.")
|
||||||
|
|
||||||
|
with open("funfacts.json", "w") as f:
|
||||||
|
json.dump(jokes, f)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bot.run("MTMyNTk1Mzg4OTcyNzQxNDM0Mw.G2Tgo0.2OhbgaVYhys0BhxJMVgGDnG0W5qvxH-soJML3M")
|
bot.run("MTMyNTk1Mzg4OTcyNzQxNDM0Mw.G2Tgo0.2OhbgaVYhys0BhxJMVgGDnG0W5qvxH-soJML3M")
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user