Skip to content

Commit f1bfe03

Browse files
committed
ref: minor various changes
1 parent 8610d44 commit f1bfe03

File tree

4 files changed

+47
-33
lines changed

4 files changed

+47
-33
lines changed

cogs/helloworld.py

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import os
77

88
import interactions
9+
910
from interactions import (
1011
ActionRow,
1112
Button,
@@ -98,8 +99,10 @@ async def _selectmenu_respone(
9899
async def hello_cmd(
99100
self,
100101
ctx: interactions.CommandContext,
102+
# The next two keyword args cannot be changed. This is how you determine sub commands
101103
sub_command: str,
102104
sub_command_group: str = None,
105+
# The option we declare in our sub commands
103106
message: str = None,
104107
):
105108
if sub_command == "world":

cogs/helloworld_legacy.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ async def _selectmenu_respone(
4343
"""Registers to the select menu"""
4444
await ctx.send(f"You picked: {options[0]}", ephemeral=True)
4545

46+
# Now the actual commands
4647
@interactions.extension_command(
4748
name="helloworld",
4849
description="The simplest of commands",
@@ -144,6 +145,7 @@ async def hellocomponents(
144145

145146

146147
def setup(client: interactions.Client):
147-
"Skip loading this"
148-
# HelloWorldOld(client)
148+
"""Skip loading this
149+
HelloWorldOld(client)
150+
"""
149151
pass

main.py

+3-10
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,15 @@
4141
logger.critical("TOKEN variable not set. Cannot continue")
4242
sys.exit(1)
4343

44-
client = interactions.Client(token=TOKEN, disable_sync=True)
44+
# Set disable_sync to True when not editing your commands (name, description, options, etc.)
45+
client = interactions.Client(token=TOKEN, disable_sync=False)
4546

4647

4748
# BEGIN on_ready
4849
@client.event
4950
async def on_ready():
5051
"""Called when bot is ready to receive interactions"""
51-
52-
# globalize this so the user may be able to use it later on
53-
global bot_user
54-
bot_user = interactions.User(**await client._http.get_self())
55-
56-
logger.info("Logged in as %s#%s" % (bot_user.username, bot_user.discriminator))
57-
58-
59-
# END on_ready
52+
logger.info("Logged in")
6053

6154

6255
# BEGIN cogs_dynamic_loader

src/logutil.py

+37-21
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,6 @@
99
import logging
1010
from config import DEBUG # pylint: disable=import-error # This works fine?
1111

12-
def get_logger(name):
13-
"""Function to get a logger
14-
Useful for modules that have already initialized a logger, such as discord.py
15-
"""
16-
__logger = logging.getLogger(name)
17-
__logger.setLevel(logging.DEBUG if DEBUG else logging.INFO)
18-
__ch = logging.StreamHandler()
19-
__ch.setFormatter(CustomFormatter())
20-
__logger.addHandler(__ch)
21-
return __logger
22-
23-
def init_logger(name="root"):
24-
"""Function to create a designated logger for separate modules"""
25-
__logger = logging.Logger(name)
26-
__ch = logging.StreamHandler()
27-
__ch.setLevel(logging.DEBUG if DEBUG else logging.INFO)
28-
__ch.setFormatter(CustomFormatter())
29-
__logger.addHandler(__ch)
30-
return __logger
31-
3212

3313
class CustomFormatter(logging.Formatter):
3414
"""Custom formatter class"""
@@ -59,9 +39,45 @@ class CustomFormatter(logging.Formatter):
5939
logging.CRITICAL: bold_red +
6040
"[%(asctime)s][%(levelname)7s] %(message)s" + reset
6141
}
62-
# Documenting my dwindling sanity here
6342

6443
def format(self, record):
6544
log_fmt = self.FORMATS.get(record.levelno)
6645
formatter = logging.Formatter(log_fmt, datefmt="%I:%M.%S%p")
6746
return formatter.format(record)
47+
48+
49+
def overwrite_ipy_loggers():
50+
for k, v in logging.Logger.manager.loggerDict.items():
51+
print(k, v)
52+
if k in [
53+
"mixin",
54+
"dispatch",
55+
"http",
56+
"gateway",
57+
"client",
58+
"context"
59+
]:
60+
for h in v.handlers:
61+
h.setFormatter(CustomFormatter)
62+
63+
64+
def get_logger(name):
65+
"""Function to get a logger
66+
Useful for modules that have already initialized a logger, such as discord.py
67+
"""
68+
__logger = logging.getLogger(name)
69+
__logger.setLevel(logging.DEBUG if DEBUG else logging.INFO)
70+
__ch = logging.StreamHandler()
71+
__ch.setFormatter(CustomFormatter())
72+
__logger.addHandler(__ch)
73+
return __logger
74+
75+
76+
def init_logger(name="root"):
77+
"""Function to create a designated logger for separate modules"""
78+
__logger = logging.Logger(name)
79+
__ch = logging.StreamHandler()
80+
__ch.setLevel(logging.DEBUG if DEBUG else logging.INFO)
81+
__ch.setFormatter(CustomFormatter())
82+
__logger.addHandler(__ch)
83+
return __logger

0 commit comments

Comments
 (0)