-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathfull_example.py
More file actions
81 lines (59 loc) · 2.75 KB
/
full_example.py
File metadata and controls
81 lines (59 loc) · 2.75 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import requests
from kickbot import KickBot, KickMessage
from datetime import datetime, timedelta
async def time_following(bot: KickBot, message: KickMessage):
""" Reply with the amount of time the user has been following for """
sender_username = message.sender.username
viewer_info = bot.moderator.get_viewer_info(sender_username)
following_since = viewer_info.get('following_since')
if following_since is not None:
reply = f"You've been following since: {following_since}"
else:
reply = "Your not currently following this channel."
await bot.reply_text(message, reply)
async def current_leaders(bot: KickBot, message: KickMessage):
""" Retrieve usernames of current leaders and send in chat"""
usernames = []
leaderboard = bot.moderator.get_leaderboard()
gift_leaders = leaderboard.get('gifts')
for user in gift_leaders:
usernames.append(user['username'])
leader_message = "Current Leaders: " + ", ".join(usernames)
await bot.send_text(leader_message)
async def tell_a_joke(bot: KickBot, message: KickMessage):
""" Reply with a random joke """
url = "https://v2.jokeapi.dev/joke/Any?type=single"
joke = requests.get(url).json().get('joke')
await bot.reply_text(message, joke)
async def current_time(bot: KickBot, message: KickMessage):
""" Reply with the current UTC time """
time = datetime.utcnow().strftime("%I:%M %p")
reply = f"Current UTC time: {time}"
await bot.reply_text(message, reply)
async def ban_if_says_gay(bot: KickBot, message: KickMessage):
""" Ban user for 20 minutes if they say 'your gay' """
sender_username = message.sender.username
ban_time = 20
bot.moderator.timeout_user(sender_username, ban_time)
async def send_links_in_chat(bot: KickBot):
""" Timed event to send social links every 30 mins """
links = "Youtube: https://youtube.com\n\nTwitch: https://twitch.tv"
await bot.send_text(links)
async def github_link(bot: KickBot, message: KickMessage):
""" Reply to '!github' command with link to github"""
reply = "Github: 'https://github.com/lukemvc'"
await bot.reply_text(message, reply)
if __name__ == '__main__':
USERBOT_EMAIL = "user@example.com"
USERBOT_PASS = "PasswordHere"
STREAMER = "streamer_username"
bot = KickBot(USERBOT_EMAIL, USERBOT_PASS)
bot.set_streamer(STREAMER)
bot.add_command_handler('!following', time_following)
bot.add_command_handler('!leaders', current_leaders)
bot.add_command_handler('!joke', tell_a_joke)
bot.add_command_handler('!time', current_time)
bot.add_command_handler('!github', github_link)
bot.add_message_handler('your gay', ban_if_says_gay)
bot.add_timed_event(timedelta(minutes=30), send_links_in_chat)
bot.poll()