-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
50 lines (38 loc) · 1.44 KB
/
main.py
File metadata and controls
50 lines (38 loc) · 1.44 KB
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
import os
from dotenv import load_dotenv
from twitchio.ext import commands
import requests
load_dotenv()
client_token = os.getenv('TOKEN')
channel = [os.getenv('CHANNEL')]
def generateJoke():
r = requests.get('https://v2.jokeapi.dev/joke/Programming?blacklistFlags=nsfw,political,racist,sexist')
joke_data = r.json()
if joke_data['type'] == 'single':
joke = joke_data['joke']
elif joke_data['type'] == 'twopart':
joke = f"{joke_data['setup']} {joke_data['delivery']}"
else:
joke = 'Oops! Something went wrong while fetching the joke.'
return joke
class Bot(commands.Bot):
def __init__(self):
# Initialise our Bot with our access token, prefix and a list of channels to join on boot...
super().__init__(token=client_token, prefix='!', initial_channels=channel)
async def event_ready(self):
# We are logged in and ready to chat and use commands...
print(f'Logged in as | {self.nick}')
print(f'User id is | {self.user_id}')
@commands.command()
async def hello(self, ctx: commands.Context):
# Send a hello back!
await ctx.send(f'Hello {ctx.author.name}!')
@commands.command()
async def github(self, ctx: commands.Context):
await ctx.send(f'https://github.com/thecodefodder')
@commands.command()
async def joke(self, ctx: commands.Context):
joke = generateJoke()
await ctx.send(joke)
bot = Bot()
bot.run()