This repository has been archived by the owner on Jan 2, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjokes.py
69 lines (52 loc) · 2.03 KB
/
jokes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from discord.ext import commands, tasks
import discord
import asyncio
import random
import os
import requests
import time
from datetime import datetime
from discord.utils import get
from discord_components import Button, ButtonStyle
import pyjokes
bot = commands.Bot(command_prefix='!')
class jokes_py(commands.Cog):
"""Buttons"""
def __init__(self, bot: commands.Bot):
self.bot = bot
@commands.command()
async def jokes(self, ctx: commands.Context):
"""Tells you funny jokes! Do !jokes"""
#sumjokes = [
# "`Don't do drugs, too expensive.`",
# "`You want joke? Here is joke. You are a failure`",
# "`A duck went to the store and bought a scooter.` ",
#"`My dolphin puns are terrible on porpoise.`",
# "`When my son told me to stop impersonating a flamingo, I had to put my foot down.`"
# ]
#jokes = random.choice(sumjokes)
jokes = pyjokes.get_joke(language="en", category="all")
components = [
[
Button(label='Like', style=ButtonStyle.green, custom_id='Like Joke'),
Button(label='Dislike', style=ButtonStyle.red, custom_id='Dislike'),
#Button(label='Subscribe', style=ButtonStyle.URL, url = link)
]
]
await ctx.send(jokes
, components=components)
@commands.Cog.listener()
async def on_button_click(self, interaction):
timestamp = datetime.now()
if interaction.custom_id == "Like Joke":
with open('joke_likes_dislike.txt', 'w') as f:
f.write("User liked a joke | Time liked: " + str(timestamp) )
f.close()
await interaction.send(f'`You have liked the joke`')
if interaction.custom_id=="Dislike":
with open('joke_likes_dislike.txt', 'w') as f:
f.write("User Disliked a joke | Time Disliked + str(timestamp)")
f.close()
await interaction.send(f'`You have disliked to joke`')
def setup(bot: commands.Bot):
bot.add_cog(jokes_py(bot))