Skip to content

Commit ec236f4

Browse files
committed
First official i.py version
1 parent c92d3a0 commit ec236f4

9 files changed

+211
-111
lines changed

README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
[![Join our Discord server](https://img.shields.io/badge/-Discord_server-blue?style=plastic&logo=discord&link=https://discord.gg/TReMEyBQsh&labelColor=black)](https://discord.gg/TReMEyBQsh)
21
# Larss_Bot
3-
The main repository for Larss_Bot#8440
42

5-
Info - https://larss-bot.onrender.com/
3+
The main repository for Larss_Bot#8440 on discord.
4+
This is a hobby project, it will (hopefully) remain free for use.

app.py

+44-40
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Bot originally made by using NAFF
22
# Ported to i.py v5
33
# pip install -U discord-py-interactions
4-
bot_official_version = "4.0.0 dev"
4+
bot_official_version = "4.0.0"
55

66
import interactions as inter
77
from interactions import (
@@ -26,6 +26,7 @@
2626
Permissions,
2727
SlashCommandChoice,
2828
ButtonStyle,
29+
check,
2930
)
3031

3132
import asyncio
@@ -103,6 +104,8 @@
103104
invite_cooldown = []
104105
nameday_cooldown = []
105106

107+
with open("data/namedays-extended.json", encoding="utf-8") as f:
108+
namedays_ext = json.load(f)
106109

107110
# @listen()
108111
# async def on_error():
@@ -111,9 +114,9 @@
111114

112115
delete_btn = Button(style=ButtonStyle.RED, custom_id="delete", emoji="🗑️")
113116

114-
base=os.path.dirname("templates/")
115-
html=open(os.path.join(base, "index.html"))
116-
soup = bs(html, 'html.parser')
117+
base = os.path.dirname("templates/")
118+
html = open(os.path.join(base, "index.html"))
119+
soup = bs(html, "html.parser")
117120

118121
# for i in range(len(epiccontribbutingppl)):
119122
# url_links_contributors.append((bot.fetch_user(epiccontribbutingppl[i])).avatar.url)
@@ -128,9 +131,9 @@
128131
</table>
129132
"""
130133

134+
131135
@listen()
132136
async def on_startup():
133-
134137
print(f"{bot.user} has connected to Discord!")
135138
# bot.load_extension("data.voice")
136139
bot.load_extension("data.ext1") # Load all games
@@ -139,21 +142,19 @@ async def on_startup():
139142
bot.load_extension("data.lichess")
140143
bot.load_extension("data.welcome")
141144

142-
contr_icons = []
143-
contr_usernames = []
144-
145-
lilhelp_icons = []
146-
lilhelp_usernames = []
145+
# contr_icons = []
146+
# contr_usernames = []
147147

148-
for contributor in epiccontribbutingppl:
149-
contr_icons.append(bot.get_user(contributor).avatar.url)
150-
contr_usernames.append(bot.get_user(contributor).username)
151-
152-
for lilhelper in lilhelpers:
153-
lilhelp_icons.append(bot.get_user(lilhelper).avatar.url)
154-
lilhelp_usernames.append(bot.get_user(lilhelper).username)
148+
# lilhelp_icons = []
149+
# lilhelp_usernames = []
155150

151+
# for contributor in epiccontribbutingppl:
152+
# contr_icons.append(bot.get_user(contributor).avatar.url)
153+
# contr_usernames.append(bot.get_user(contributor).username)
156154

155+
# for lilhelper in lilhelpers:
156+
# lilhelp_icons.append(bot.get_user(lilhelper).avatar.url)
157+
# lilhelp_usernames.append(bot.get_user(lilhelper).username)
157158

158159
# with open("index.html", "wb") as f:
159160
# f.write(soup.prettify("utf-8"))
@@ -256,6 +257,7 @@ async def reload(ctx, cog=None):
256257
else:
257258
await ctx.respond(random.choice(notauthormessages), ephemeral=True, components=[delete_btn])
258259

260+
259261
@slash_command(
260262
name="info",
261263
description="get info about the bot",
@@ -267,7 +269,7 @@ async def info(ctx):
267269
timestamp=datetime.utcnow(),
268270
color=Color.from_hex("5e50d4"),
269271
thumbnail="https://cdn.discordapp.com/attachments/983081269543993354/1041045309695987712/image.png",
270-
url="https://larss-bot.onrender.com"
272+
url="https://larss-bot.onrender.com",
271273
)
272274
embed.set_footer(text="Requested by " + str(ctx.author), icon_url=ctx.author.avatar.url)
273275
embed.add_field(
@@ -286,6 +288,10 @@ async def info(ctx):
286288
name="Last startup",
287289
value=f"<t:{int(str(now_unix)[:-2])}:R>",
288290
)
291+
embed.add_field(
292+
name="Support the creator!",
293+
value="https://ko-fi.com/larssj",
294+
)
289295

290296
btn1 = Button(label="Contributors", style=ButtonStyle.BLUE, emoji="⭐", custom_id="contributors")
291297
btn2 = Button(
@@ -305,7 +311,7 @@ async def on_component(ctx: ComponentContext):
305311
message_components = event.message.components
306312
message_components[0].components[0].disabled = True
307313
await event.message.edit(components=message_components)
308-
314+
309315
embed = Embed(
310316
title="⭐ Contributors",
311317
description=f"Awesome people who have helped to make Larss_Bot what it is today!",
@@ -339,7 +345,7 @@ async def on_component(ctx: ComponentContext):
339345
message_components = event.message.components
340346
message_components[0].components[1].disabled = True
341347
await event.message.edit(components=message_components)
342-
348+
343349
embed = Embed(
344350
title="Partner servers",
345351
description=f"Press any of the buttons below to get invited to one of the partnered servers",
@@ -369,27 +375,23 @@ async def on_component(ctx: ComponentContext):
369375
url="https://discord.gg/w78rcjW8ck",
370376
)
371377
components: list[ActionRow] = spread_to_rows(btn1, btn2, btn3)
372-
components.append(ActionRow(delete_btn))
378+
components.append(ActionRow(delete_btn))
373379

374380
await event.send(embed=embed, components=components)
375-
# if event.custom_id == "extendedlistshow":
376-
# if event.channel.id not in nameday_cooldown:
377-
# today = date.today().strftime("%m-%d")
378-
# embed = Embed(
379-
# title="Visi šodienas vārdi",
380-
# description="> " + "\n> ".join(namedays_ext[today]),
381-
# color=Color.from_rgb(255, 13, 13),
382-
# )
383-
# await event.send(embed=embed)
384-
# nameday_cooldown.append(event.channel.id)
385-
# await asyncio.sleep(15)
386-
# nameday_cooldown.remove(event.channel.id)
387-
# else:
388-
# # ephemeral not gonna work, once again
389-
# await event.send(
390-
# "Looks like someone already pressed the button. No need to do it again.",
391-
# ephemeral=True,
392-
# )
381+
case "extendedlistshow":
382+
today = date.today().strftime("%m-%d")
383+
embed = Embed(
384+
title="Visi šodienas vārdi",
385+
description="> " + "\n> ".join(namedays_ext[today]),
386+
color=Color.from_rgb(255, 13, 13),
387+
)
388+
389+
message_components = event.message.components
390+
message_components[0].components[0].disabled = True
391+
await event.message.edit(components=message_components)
392+
393+
await event.send(embed=embed, components=[delete_btn])
394+
393395
case "delete":
394396
if (
395397
event.message.interaction._user_id == event.author.id
@@ -399,6 +401,7 @@ async def on_component(ctx: ComponentContext):
399401
else:
400402
await event.send("Not your interaction.", ephemeral=True)
401403

404+
402405
@slash_command(name="ping", description="check the bots status")
403406
async def ping(ctx):
404407
message = await ctx.send(
@@ -430,7 +433,7 @@ async def ping(ctx):
430433
)
431434
async def randomise(ctx, min, max):
432435
try:
433-
#check if the numbers are floats
436+
# check if the numbers are floats
434437
try:
435438
min = int(min)
436439
max = int(max)
@@ -491,6 +494,7 @@ async def randomise(ctx, min, max):
491494

492495
# # await bot.process_commands(message)
493496

497+
494498
@is_owner()
495499
@slash_command("quit", description="Log off the bot")
496500
async def quit(ctx: InteractionContext):

data/configcmds.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import interactions
2+
from interactions import (
3+
Extension,
4+
slash_command,
5+
slash_option,
6+
Color,
7+
SlashContext,
8+
)
9+
10+
class ConfigCMDs(Extension):
11+
# /config namedays
12+
@slash_command(
13+
name="config",
14+
description="Configurate the bot for your server",
15+
group_name="namedays",
16+
group_description="Configure the nameday command",
17+
)
18+
async def my_command_function(ctx: SlashContext):
19+
await ctx.send("Hello, World!")
20+
21+
22+
def setup(bot):
23+
ConfigCMDs(bot)

data/ext1.py

+62-62
Original file line numberDiff line numberDiff line change
@@ -81,68 +81,68 @@ async def spotify(self, ctx):
8181
# await message.add_reaction("<:smash:1023135175237980231>")
8282
# await message.add_reaction("<:pass:1023135160310448191>")
8383

84-
# @slash_command(name="vd", description="Get latvian namedays.")
85-
# @slash_option(
86-
# name="name",
87-
# description="Input a name to get nameday date.",
88-
# required=False,
89-
# opt_type=OptionType.STRING,
90-
# )
91-
# async def nameday(self, ctx, name=None):
92-
# if name == None:
93-
# components = [
94-
# ActionRow(
95-
# Button(
96-
# label="Rādīt visus",
97-
# style=ButtonStyle.RED,
98-
# custom_id="extendedlistshow",
99-
# emoji="🗓",
100-
# )
101-
# ),
102-
# ]
103-
# today = date.today().strftime("%m-%d")
104-
# embed = Embed(
105-
# title="Šodien vārda dienu svin:",
106-
# description=", ".join(namedays[today]),
107-
# color=Color.from_rgb(255, 13, 13),
108-
# )
109-
# embed.set_thumbnail(
110-
# url="https://cdn.discordapp.com/attachments/930891009007710218/1006812016675135568/IMG_7631.jpg"
111-
# )
112-
# await ctx.send(embed=embed, components=components)
113-
# else:
114-
# nday = None
115-
# for k in namedays.keys():
116-
# v = namedays[k] + namedays_ext[k]
117-
# if name in v:
118-
# nday = datetime.strptime("2000-" + k, "%Y-%m-%d").date()
119-
# nday_text = format_date(date=nday, format="d. MMMM", locale="lv")
120-
# if nday_text.endswith("is"):
121-
# unedited_ndaytext = nday_text
122-
# nday_text = nday_text[:-2] + "ī"
123-
# else:
124-
# unedited_ndaytext = nday_text
125-
# nday_text = nday_text[:-1] + "ā"
126-
127-
# embed = Embed(
128-
# title=f"{unedited_ndaytext}",
129-
# description=f"{name} vārda dienu svin {nday_text}",
130-
# color=Color.from_rgb(255, 13, 13),
131-
# )
132-
# embed.set_thumbnail(
133-
# url="https://cdn.discordapp.com/attachments/930891009007710218/1006812016675135568/IMG_7631.jpg"
134-
# )
135-
136-
# if nday is None:
137-
# embed = Embed(
138-
# title="Error_",
139-
# description=f"Kalendārā neatradu '{name}'",
140-
# color=Color.from_rgb(255, 13, 13),
141-
# )
142-
# embed.set_thumbnail(
143-
# url="https://cdn.discordapp.com/attachments/930891009007710218/1006812016675135568/IMG_7631.jpg"
144-
# )
145-
# await ctx.send(embed=embed)
84+
@slash_command(name="vd", description="Get latvian namedays.")
85+
@slash_option(
86+
name="name",
87+
description="Input a name to get nameday date.",
88+
required=False,
89+
opt_type=OptionType.STRING,
90+
)
91+
async def nameday(self, ctx, name=None):
92+
if name == None:
93+
components = [
94+
ActionRow(
95+
Button(
96+
label="Rādīt visus",
97+
style=ButtonStyle.RED,
98+
custom_id="extendedlistshow",
99+
emoji="🗓",
100+
), delete_btn
101+
),
102+
]
103+
today = date.today().strftime("%m-%d")
104+
embed = Embed(
105+
title="Šodien vārda dienu svin:",
106+
description=", ".join(namedays[today]),
107+
color=Color.from_rgb(255, 13, 13),
108+
)
109+
embed.set_thumbnail(
110+
url="https://cdn.discordapp.com/attachments/930891009007710218/1006812016675135568/IMG_7631.jpg"
111+
)
112+
await ctx.send(embed=embed, components=components)
113+
else:
114+
nday = None
115+
for k in namedays.keys():
116+
v = namedays[k] + namedays_ext[k]
117+
if name in v:
118+
nday = datetime.strptime("2000-" + k, "%Y-%m-%d").date()
119+
nday_text = format_date(date=nday, format="d. MMMM", locale="lv")
120+
if nday_text.endswith("is"):
121+
unedited_ndaytext = nday_text
122+
nday_text = nday_text[:-2] + "ī"
123+
else:
124+
unedited_ndaytext = nday_text
125+
nday_text = nday_text[:-1] + "ā"
126+
127+
embed = Embed(
128+
title=f"{unedited_ndaytext}",
129+
description=f"{name} vārda dienu svin {nday_text}",
130+
color=Color.from_rgb(255, 13, 13),
131+
)
132+
embed.set_thumbnail(
133+
url="https://cdn.discordapp.com/attachments/930891009007710218/1006812016675135568/IMG_7631.jpg"
134+
)
135+
136+
if nday is None:
137+
embed = Embed(
138+
title="Error_",
139+
description=f"Kalendārā neatradu '{name}'",
140+
color=Color.from_rgb(255, 13, 13),
141+
)
142+
embed.set_thumbnail(
143+
url="https://cdn.discordapp.com/attachments/930891009007710218/1006812016675135568/IMG_7631.jpg"
144+
)
145+
await ctx.send(embed=embed, components=[delete_btn])
146146

147147
# await dm.send(embed=embed)
148148
@slash_command(name="calculate", description="calculate some numbers")

0 commit comments

Comments
 (0)