Skip to content

Commit c004e0f

Browse files
Move to extensions
1 parent a45ec76 commit c004e0f

File tree

5 files changed

+168
-110
lines changed

5 files changed

+168
-110
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,6 @@ dmypy.json
127127

128128
# Pyre type checker
129129
.pyre/
130+
131+
# LNO Cog
132+
src/extesions/lno.py

bot.py src/bot.py

+6-110
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
import asyncio
22
import datetime
3-
import sys
4-
import traceback
5-
import typing
63

74
import disnake
85
import humanfriendly
96
import pymongo
10-
import topgg
7+
# import topgg
118
from async_timeout import timeout
129
from disnake.ext import commands, tasks
1310
from dotenv import dotenv_values
14-
from statcord import StatcordClient
11+
# from statcord import StatcordClient
1512

1613
token = dotenv_values(".env")["DISCORD"]
1714
upsince = datetime.datetime.now()
@@ -35,29 +32,9 @@
3532
role_menus = db.role_menus
3633
polls = db.polls
3734

38-
def create_role_menu(guild_id: int, channel_id: int, message_id: int, roles: list):
39-
data = {
40-
"guild_id": guild_id,
41-
"channel_id": channel_id,
42-
"message_id": message_id,
43-
"roles": roles
44-
}
45-
if role_menus.find_one({"message_id": message_id}) != None:
46-
return False
47-
role_menus.insert_one(data)
48-
return True
49-
50-
def create_poll(guild_id: int, message_id: int, options: list):
51-
data = {
52-
"guild_id": guild_id,
53-
"channel_id": channel_id,
54-
"message_id": message_id,
55-
"votes": []
56-
}
57-
if polls.find_one({"message_id": message_id}) != None:
58-
return False
59-
polls.insert_one(data)
60-
return True
35+
bot.load_extension("extesions/polls")
36+
bot.load_extension("extesions/rolemenus")
37+
# bot.load_extension("extesions/lno")
6138

6239
class Tasks(commands.Cog):
6340

@@ -173,92 +150,11 @@ async def info(inter: disnake.ApplicationCommandInteraction):
173150
)
174151
await inter.send(content=None, embed=embed, view=InfoButtons())
175152

176-
class PollDropdown(disnake.ui.Select):
177-
def __init__(self, poll_options, title, min_choices, max_choices):
178-
self.options = []
179-
self.votes = polls.find_one() #TODO
180-
self.total_votes = []
181-
for count, i in enumerate(poll_options):
182-
vote_count = votes[count]
183-
self.options.append(disnake.SelectOption(
184-
label=i,
185-
description=f"{votes} vote{'' if len(vote_count) == 1 else 's'}"
186-
))
187-
super().__init__(
188-
placeholder=title,
189-
min_values=min_choices,
190-
max_values=max_choices,
191-
options=self.options,
192-
)
193-
async def callback(inter: disnake.MessageInteraction):
194-
for i in self.values:
195-
self.votes[i] += 1
196-
embed = discord.Embed(title=title, description=f"Total votes: {self.total_votes}")
197-
for count, i in enumerate(self.options):
198-
blocks_filled = "🟦" * int((self.votes[count]/self.total_votes)*10)
199-
blocks_empty = "⬜" * int((10-(self.votes[count]/self.total_votes))*10)
200-
embed.add_field(
201-
name=i,
202-
value=f"{blocks_filled}{blocks_empty} ({self.votes[count]})"
203-
)
204-
await inter.response.edit_message(embed=embed)
205-
206-
class PollView(disnake.ui.View):
207-
def __init__(self, poll_options, title, min_choices, max_choices):
208-
super().__init__()
209-
self.add_item(SinglePollDropdown(poll_options, title, min_choices, max_choices))
210-
211-
@bot.slash_command(description="Make a poll. Seperate each option with a comma.")
212-
async def poll(
213-
inter: disnake.ApplicationCommandInteraction,
214-
title: str,
215-
options: str,
216-
min_choices = commands.Param(default=1, ge=1, le=24),
217-
max_choices = commands.Param(default=1, ge=1, le=25)):
218-
poll_options = options.split(",")[:25]
219-
[i.strip() for i in poll_options]
220-
[i[:25] for i in poll_options]
221-
create_poll(inter.guild.id, inter.channel.id, inter.id)
222-
embed = discord.Embed(title=title)
223-
for i in options:
224-
embed.add_field(
225-
name=i,
226-
value="⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜ (0)"
227-
)
228-
await inter.send(content=None, embed=embed, view=SinglePollView(poll_options, title, min_choices, max_choices))
229-
230-
###
231-
232-
def has_role_permissions():
233-
pass
234-
235-
@bot.slash_command(description="Make a role menu. Use /add_role_to_menu to add more roles.")
236-
async def role_menu(inter: disnake.ApplicationCommandInteraction, title: str, description: str = None):
237-
pass
238-
239-
@bot.slash_command(description="Adds a role to a role menu.")
240-
async def add_role_to_menu(inter: disnake.ApplicationCommandInteraction, message_id: int, role: disnake.Role, emoji: disnake.Emoji = None):
241-
pass
242-
243-
@bot.slash_command(description="Removes a role to a role menu.")
244-
async def remove_role_from_menu(inter: disnake.ApplicationCommandInteraction, message_id: int, position: int = commands.Param(ge=1, le=25)):
245-
pass
246-
247-
@bot.slash_command(description="Makes a role button message.")
248-
async def role_button(
249-
inter: disnake.ApplicationCommandInteraction,
250-
role: disnake.Role,
251-
message_title: str,
252-
button_color: str = commands.Param(choices=["Blurple", "Gray", "Green", "Red"]),
253-
message_description: str = None,
254-
button_emoji: disnake.Emoji = None):
255-
pass
256-
257153
bot.remove_command("help")
258154
bot.add_cog(Tasks(bot))
259155

260156
@bot.event
261157
async def on_ready():
262158
print("-----\nReady\n-----\n")
263159

264-
bot.run(token)
160+
bot.run(token)

src/extensions/lno.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import asyncio
2+
import datetime
3+
4+
import disnake
5+
from async_timeout import timeout
6+
from disnake.ext import commands, tasks

src/extensions/polls.py

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import asyncio
2+
import datetime
3+
4+
import disnake
5+
import pymongo
6+
from async_timeout import timeout
7+
from disnake.ext import commands, tasks
8+
9+
mongoclient = pymongo.MongoClient()
10+
db = mongoclient.modernbot
11+
guild_preferences = db.guild_preferences
12+
polls = db.polls
13+
14+
def create_poll(guild_id: int, message_id: int, options: list):
15+
data = {
16+
"guild_id": guild_id,
17+
"message_id": message_id,
18+
"votes": []
19+
}
20+
if polls.find_one({"message_id": message_id}) != None:
21+
return False
22+
polls.insert_one(data)
23+
return True
24+
25+
26+
class PollDropdown(disnake.ui.Select):
27+
def __init__(self, poll_options, title, min_choices, max_choices):
28+
self.options = []
29+
self.title = title
30+
self.votes = polls.find_one() # TODO
31+
self.total_votes = []
32+
for count, i in enumerate(poll_options):
33+
vote_count = self.votes[count]
34+
self.options.append(disnake.SelectOption(
35+
label=i,
36+
description=f"{self.votes} vote{'' if len(vote_count) == 1 else 's'}"
37+
))
38+
super().__init__(
39+
placeholder=title,
40+
min_values=min_choices,
41+
max_values=max_choices,
42+
options=self.options,
43+
)
44+
45+
async def callback(self, inter: disnake.MessageInteraction):
46+
for i in self.values:
47+
self.votes[i] += 1
48+
embed = disnake.Embed(
49+
title=self.title, description=f"Total votes: {self.total_votes}")
50+
for count, i in enumerate(self.options):
51+
blocks_filled = "🟦" * int((self.votes[count]/self.total_votes)*10)
52+
blocks_empty = "⬜" * int((10-(self.votes[count]/self.total_votes))*10)
53+
embed.add_field(
54+
name=i,
55+
value=f"{blocks_filled}{blocks_empty} ({self.votes[count]})"
56+
)
57+
await inter.response.edit_message(embed=embed)
58+
59+
60+
class PollView(disnake.ui.View):
61+
def __init__(self, poll_options, title, min_choices, max_choices):
62+
super().__init__()
63+
self.add_item(PollDropdown(poll_options, title, min_choices, max_choices))
64+
65+
66+
@commands.slash_command(description="Make a poll. Seperate each option with a comma.")
67+
async def poll(
68+
inter: disnake.ApplicationCommandInteraction,
69+
title: str,
70+
options: str,
71+
min_choices=commands.Param(default=1, ge=1, le=24),
72+
max_choices=commands.Param(default=1, ge=1, le=25)):
73+
poll_options = options.split(",")[:25]
74+
[i.strip() for i in poll_options]
75+
[i[:25] for i in poll_options]
76+
create_poll(inter.guild.id, inter.channel.id, inter.id)
77+
embed = disnake.Embed(title=title)
78+
for i in options:
79+
embed.add_field(
80+
name=i,
81+
value="⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜ (0)"
82+
)
83+
await inter.send(content=None, embed=embed, view=PollView(poll_options, title, min_choices, max_choices))
84+
85+
86+
def autocomplete_title(inter: disnake.ApplicationCommandInteraction, user_input: str):
87+
guild_polls = polls.find_many({"guild_id": inter.guild.id})
88+
open_polls = []
89+
for i in guild_polls:
90+
open_polls.append(guild_polls["title"])
91+
return [i for i in open_polls if user_input in i]
92+
93+
@commands.slash_command(description="Close a poll.")
94+
async def close_poll(inter: disnake.ApplicationCommandInteraction, title: str = commands.Param(autocomplete=autocomplete_title)):
95+
# Condition: must be mod or poll author
96+
# TODO: Get message
97+
# message.edit_original(view=None)
98+
polls.delete_one({"message_id": inter.id})
99+
await inter.send("Poll closed.")

src/extensions/rolemenus.py

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import asyncio
2+
import datetime
3+
4+
import disnake
5+
import pymongo
6+
from async_timeout import timeout
7+
from disnake.ext import commands, tasks
8+
9+
mongoclient = pymongo.MongoClient()
10+
db = mongoclient.modernbot
11+
guild_preferences = db.guild_preferences
12+
role_menus = db.role_menus
13+
14+
def create_role_menu(guild_id: int, channel_id: int, message_id: int, roles: list):
15+
data = {
16+
"guild_id": guild_id,
17+
"channel_id": channel_id,
18+
"message_id": message_id,
19+
"roles": roles
20+
}
21+
if role_menus.find_one({"message_id": message_id}) != None:
22+
return False
23+
role_menus.insert_one(data)
24+
return True
25+
26+
def has_role_permissions():
27+
pass
28+
29+
30+
@commands.slash_command(description="Make a role menu. Use /add_role_to_menu to add more roles.")
31+
async def role_menu(inter: disnake.ApplicationCommandInteraction, title: str, description: str = None):
32+
pass
33+
34+
35+
@commands.slash_command(description="Adds a role to a role menu.")
36+
async def add_role_to_menu(inter: disnake.ApplicationCommandInteraction, message_id: int, role: disnake.Role, emoji: disnake.Emoji = None):
37+
pass
38+
39+
40+
@commands.slash_command(description="Removes a role to a role menu.")
41+
async def remove_role_from_menu(inter: disnake.ApplicationCommandInteraction, message_id: int, position: int = commands.Param(ge=1, le=25)):
42+
pass
43+
44+
45+
@commands.slash_command(description="Makes a role button message.")
46+
async def role_button(
47+
inter: disnake.ApplicationCommandInteraction,
48+
role: disnake.Role,
49+
message_title: str,
50+
button_color: str = commands.Param(
51+
choices=["Blurple", "Gray", "Green", "Red"]),
52+
message_description: str = None,
53+
button_emoji: disnake.Emoji = None):
54+
pass

0 commit comments

Comments
 (0)