-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
74 lines (67 loc) · 2.24 KB
/
bot.py
File metadata and controls
74 lines (67 loc) · 2.24 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
"""
Bot Class
"""
import datetime
from twitchio.ext import commands
from config.config_manager import (
load_oauth_config,
load_bot_config,
CredentialManager,
BotSettings,
)
class Bot(commands.Bot):
"""
Initializes twitch bot object with available commands
"""
def __init__(self):
# Initialise our Bot with our access token
self.credentials_object: CredentialManager = load_oauth_config()
self.bot_settings_object: BotSettings = load_bot_config()
self.bot_name = self.bot_settings_object.bot_name
self.bot_version = self.bot_settings_object.bot_version
super().__init__(
token=self.credentials_object.oauth_token,
prefix=self.bot_settings_object.bot_command_prefix,
initial_channels=[self.credentials_object.channel_name],
)
async def event_ready(self):
"""
Logged in and ready
"""
print(f"Logged in as | {self.nick}")
@commands.command()
async def hello(self, ctx: commands.Context):
"""
Command to respond hi to user
"""
await ctx.send(f"Hello {ctx.author.name}!")
@commands.command()
async def version(self, ctx: commands.Context):
"""
Command to respond hi to user
"""
await ctx.send(f"{self.bot_name} {self.bot_version}!")
@commands.command()
async def uptime(self, ctx: commands.Context):
"""
Command to print stream uptime
"""
stream_info = await self.fetch_streams(
None, None, [self.credentials_object.channel_name]
)
if len(stream_info) > 0:
start_time = stream_info[0].started_at.replace(tzinfo=None)
current_time = datetime.datetime.now()
time_difference = (current_time - start_time).seconds
days = divmod(time_difference, 86400)
hours = divmod(days[1], 3600)
minutes = divmod(hours[1], 60)
time_string = f"""
{days[0]} days,
{hours[0]} hours,
{minutes[0]} minutes,
{minutes[1]} seconds
"""
await ctx.send(f"Uptime: {time_string}!")
else:
await ctx.send("Uptime: Not Live!")