-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHomeMain.py
More file actions
143 lines (105 loc) · 4.89 KB
/
HomeMain.py
File metadata and controls
143 lines (105 loc) · 4.89 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env python3
import discord
from discord.ext import commands
import settings
intents = discord.Intents.default()
intents.message_content = True
client = commands.Bot(command_prefix="!", intents=intents)
client.remove_command("help")
logger = settings.logging.getLogger("bot")
@client.event
async def on_ready():
"""Reports when main bot is ready"""
for file in settings.COGS_DIR_PATH.iterdir():
if file.suffix == ".py":
await client.load_extension(f"{settings.COGS_DIR}.{file.stem}")
logger.info(f"User: {client.user} (ID: {client.user.id}). HomeMain core startup")
@client.event
async def on_command_error(ctx, error):
if isinstance(error, commands.CommandNotFound):
await ctx.send("Error. Command not found")
@client.command()
async def ping(ctx):
"""Returns latency between bot and server"""
await ctx.send(f"Pong. {round(client.latency * 1000)}ms")
@client.group(invoke_without_command=True)
async def help(ctx):
"""Custom bot help command"""
embed = discord.Embed(
title="HomeBot Help Menu",
description="Bot command prefix: !",
colour=discord.Colour.blue()
)
# # airport.py
embed.add_field(name="!metar [airport_code]", value="> Airport METAR report", inline=True)
embed.add_field(name="!taf [airport_code]", value="> Airport TAF report", inline=True)
embed.add_field(name="!wx [airport_code]", value="> Airport full METAR/TAF report", inline=True)
# covid19.py
embed.add_field(name="!covid", value="> Request Ireland COVID-19 Data", inline=True)
# # f1.py
embed.add_field(name="!f1", value="> Request F1 (Full) Schedule", inline=True)
embed.add_field(name="!f1.next", value="> Request F1 (Next) Schedule", inline=True)
embed.add_field(name="!wdc", value="> Request F1 WDC Standings", inline=True)
embed.add_field(name="!wcc", value="> Request F1 WCC Standings", inline=True)
embed.set_thumbnail(url="https://raw.githubusercontent.com/ianlibasora/HomeBot/master/images/home.png")
embed.set_footer(icon_url=ctx.author.avatar.url, text=f"Requested by {ctx.author}")
embed.set_author(name="HomeBot", icon_url="https://raw.githubusercontent.com/ianlibasora/HomeBot/master/images/home.png")
await ctx.send(embed=embed)
@client.command()
async def load(ctx, path):
"""Loads cogs"""
try:
await client.load_extension(f"{settings.COGS_DIR}.{path}")
logger.info(f"User: {ctx.author} (ID: {ctx.author.id}). Cog ({path}) loaded")
await ctx.send(f"Cog ({path}) loaded")
except Exception:
logger.warning(f"User: {ctx.author} (ID: {ctx.author.id}). Failed to load Cog ({path})")
await ctx.send(f"Failed to load Cog ({path})")
@load.error
async def loadError(ctx, error):
if isinstance(error, commands.MissingRequiredArgument):
await ctx.send("Missing required argument(s). Eg. !load [path]")
@client.command()
async def unload(ctx, path):
"""Unloads cogs"""
try:
await client.unload_extension(f"{settings.COGS_DIR}.{path}")
logger.info(f"User: {ctx.author} (ID: {ctx.author.id}). Cog ({path}) unloaded")
await ctx.send(f"Cog ({path}) unloaded")
except Exception:
logger.warning(f"User: {ctx.author} (ID: {ctx.author.id}). Failed to unload Cog ({path})")
await ctx.send(f"Failed to unload Cog ({path})")
@unload.error
async def unloadError(ctx, error):
if isinstance(error, commands.MissingRequiredArgument):
await ctx.send("Missing required argument(s). Eg. !unload [path]")
@client.command()
async def reload(ctx, path):
"""Reloads cog"""
try:
await client.unload_extension(f"{settings.COGS_DIR}.{path}")
await client.load_extension(f"{settings.COGS_DIR}.{path}")
logger.info(f"User: {ctx.author} (ID: {ctx.author.id}). Cog ({path}) reloaded")
await ctx.send(f"Cog ({path}) reloaded")
except Exception:
logger.warning(f"User: {ctx.author} (ID: {ctx.author.id}). Failed to reload Cog ({path})")
await ctx.send(f"Failed to reload Cog ({path})")
@reload.error
async def reloadError(ctx, error):
if isinstance(error, commands.MissingRequiredArgument):
await ctx.send("Missing required argument(s). Eg. !reload [path]")
@client.command()
async def freload(ctx):
"""Reload all cogs"""
try:
for file in settings.COGS_DIR_PATH.iterdir():
if file.suffix == ".py":
await client.unload_extension(f"{settings.COGS_DIR}.{file.stem}")
await client.load_extension(f"{settings.COGS_DIR}.{file.stem}")
logger.info(f"User: {ctx.author} (ID: {ctx.author.id}). Reloaded all cogs")
await ctx.send("Reloaded all cogs")
except Exception:
logger.warning(f"User: {ctx.author} (ID: {ctx.author.id}). Failed to reload Cogs")
await ctx.send(f"Failed to reload Cogs")
if __name__ == "__main__":
client.run(settings.BOT_TOKEN, root_logger=True)