mycord 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mycord-0.1.0/PKG-INFO +5 -0
- mycord-0.1.0/README.md +2 -0
- mycord-0.1.0/mycord/__init__.py +2 -0
- mycord-0.1.0/mycord/bot.py +123 -0
- mycord-0.1.0/mycord/context.py +19 -0
- mycord-0.1.0/mycord/env.py +23 -0
- mycord-0.1.0/mycord/ui.py +21 -0
- mycord-0.1.0/mycord.egg-info/PKG-INFO +5 -0
- mycord-0.1.0/mycord.egg-info/SOURCES.txt +12 -0
- mycord-0.1.0/mycord.egg-info/dependency_links.txt +1 -0
- mycord-0.1.0/mycord.egg-info/requires.txt +1 -0
- mycord-0.1.0/mycord.egg-info/top_level.txt +1 -0
- mycord-0.1.0/setup.cfg +4 -0
- mycord-0.1.0/setup.py +8 -0
mycord-0.1.0/PKG-INFO
ADDED
mycord-0.1.0/README.md
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import discord
|
|
2
|
+
import os
|
|
3
|
+
import importlib
|
|
4
|
+
|
|
5
|
+
from .context import Context
|
|
6
|
+
from .ui import MyView
|
|
7
|
+
|
|
8
|
+
class Bot(discord.Client):
|
|
9
|
+
|
|
10
|
+
def __init__(self, prefix="!", **kwargs):
|
|
11
|
+
|
|
12
|
+
intents = kwargs.pop(
|
|
13
|
+
"intents",
|
|
14
|
+
discord.Intents.all()
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
super().__init__(intents=intents, **kwargs)
|
|
18
|
+
|
|
19
|
+
self.prefix = prefix
|
|
20
|
+
|
|
21
|
+
self.commands = {}
|
|
22
|
+
self.buttons = []
|
|
23
|
+
|
|
24
|
+
# =========================================
|
|
25
|
+
# COMMANDS
|
|
26
|
+
# =========================================
|
|
27
|
+
|
|
28
|
+
def command(self):
|
|
29
|
+
|
|
30
|
+
def wrapper(func):
|
|
31
|
+
|
|
32
|
+
self.commands[func.__name__] = func
|
|
33
|
+
return func
|
|
34
|
+
|
|
35
|
+
return wrapper
|
|
36
|
+
|
|
37
|
+
# =========================================
|
|
38
|
+
# BUTTONS
|
|
39
|
+
# =========================================
|
|
40
|
+
|
|
41
|
+
def button(self, label, style=discord.ButtonStyle.green):
|
|
42
|
+
|
|
43
|
+
def wrapper(func):
|
|
44
|
+
|
|
45
|
+
self.buttons.append({
|
|
46
|
+
"label": label,
|
|
47
|
+
"style": style,
|
|
48
|
+
"callback": func
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
return func
|
|
52
|
+
|
|
53
|
+
return wrapper
|
|
54
|
+
|
|
55
|
+
# =========================================
|
|
56
|
+
# CONTEXT CREATION
|
|
57
|
+
# =========================================
|
|
58
|
+
|
|
59
|
+
async def on_message(self, message):
|
|
60
|
+
|
|
61
|
+
if message.author.bot:
|
|
62
|
+
return
|
|
63
|
+
|
|
64
|
+
if not message.content.startswith(self.prefix):
|
|
65
|
+
return
|
|
66
|
+
|
|
67
|
+
args = message.content[len(self.prefix):].split()
|
|
68
|
+
|
|
69
|
+
if not args:
|
|
70
|
+
return
|
|
71
|
+
|
|
72
|
+
cmd = args[0]
|
|
73
|
+
|
|
74
|
+
ctx = Context(self, message)
|
|
75
|
+
|
|
76
|
+
if cmd in self.commands:
|
|
77
|
+
|
|
78
|
+
await self.commands[cmd](ctx)
|
|
79
|
+
|
|
80
|
+
# =========================================
|
|
81
|
+
# BUTTON SENDER
|
|
82
|
+
# =========================================
|
|
83
|
+
|
|
84
|
+
async def send_buttons(self, channel, content):
|
|
85
|
+
|
|
86
|
+
view = MyView(self.buttons)
|
|
87
|
+
|
|
88
|
+
await channel.send(
|
|
89
|
+
content,
|
|
90
|
+
view=view
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
# =========================================
|
|
94
|
+
# EVENTS (RAW DISCORD HOOK)
|
|
95
|
+
# =========================================
|
|
96
|
+
|
|
97
|
+
def event(self, func):
|
|
98
|
+
|
|
99
|
+
setattr(self, func.__name__, func)
|
|
100
|
+
|
|
101
|
+
return func
|
|
102
|
+
|
|
103
|
+
# =========================================
|
|
104
|
+
# COG LOADER
|
|
105
|
+
# =========================================
|
|
106
|
+
|
|
107
|
+
def load_cogs(self, folder="cogs"):
|
|
108
|
+
|
|
109
|
+
for file in os.listdir(f"./{folder}"):
|
|
110
|
+
|
|
111
|
+
if file.endswith(".py"):
|
|
112
|
+
|
|
113
|
+
name = file[:-3]
|
|
114
|
+
|
|
115
|
+
module = importlib.import_module(
|
|
116
|
+
f"{folder}.{name}"
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
if hasattr(module, "setup"):
|
|
120
|
+
|
|
121
|
+
module.setup(self)
|
|
122
|
+
|
|
123
|
+
print(f"Loaded cog: {name}")
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
class Context:
|
|
2
|
+
|
|
3
|
+
def __init__(self, bot, message):
|
|
4
|
+
|
|
5
|
+
self.bot = bot
|
|
6
|
+
self.message = message
|
|
7
|
+
|
|
8
|
+
self.author = message.author
|
|
9
|
+
self.guild = message.guild
|
|
10
|
+
self.channel = message.channel
|
|
11
|
+
self.content = message.content
|
|
12
|
+
|
|
13
|
+
async def send(self, content=None, embed=None, view=None):
|
|
14
|
+
|
|
15
|
+
return await self.channel.send(
|
|
16
|
+
content=content,
|
|
17
|
+
embed=embed,
|
|
18
|
+
view=view
|
|
19
|
+
)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
_loaded = False
|
|
4
|
+
|
|
5
|
+
def env(key):
|
|
6
|
+
|
|
7
|
+
global _loaded
|
|
8
|
+
|
|
9
|
+
if not _loaded and os.path.exists(".env"):
|
|
10
|
+
|
|
11
|
+
with open(".env") as f:
|
|
12
|
+
|
|
13
|
+
for line in f:
|
|
14
|
+
|
|
15
|
+
if "=" in line:
|
|
16
|
+
|
|
17
|
+
k, v = line.strip().split("=", 1)
|
|
18
|
+
|
|
19
|
+
os.environ[k] = v
|
|
20
|
+
|
|
21
|
+
_loaded = True
|
|
22
|
+
|
|
23
|
+
return os.getenv(key)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import discord
|
|
2
|
+
|
|
3
|
+
class MyView(discord.ui.View):
|
|
4
|
+
|
|
5
|
+
def __init__(self, buttons):
|
|
6
|
+
|
|
7
|
+
super().__init__()
|
|
8
|
+
|
|
9
|
+
for b in buttons:
|
|
10
|
+
|
|
11
|
+
async def callback(interaction, data=b):
|
|
12
|
+
|
|
13
|
+
await data["callback"](interaction)
|
|
14
|
+
|
|
15
|
+
button = discord.ui.Button(
|
|
16
|
+
label=b["label"],
|
|
17
|
+
style=b["style"]
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
button.callback = callback
|
|
21
|
+
self.add_item(button)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
setup.py
|
|
3
|
+
mycord/__init__.py
|
|
4
|
+
mycord/bot.py
|
|
5
|
+
mycord/context.py
|
|
6
|
+
mycord/env.py
|
|
7
|
+
mycord/ui.py
|
|
8
|
+
mycord.egg-info/PKG-INFO
|
|
9
|
+
mycord.egg-info/SOURCES.txt
|
|
10
|
+
mycord.egg-info/dependency_links.txt
|
|
11
|
+
mycord.egg-info/requires.txt
|
|
12
|
+
mycord.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
discord.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
mycord
|
mycord-0.1.0/setup.cfg
ADDED