Skip to content

Commit 03eb437

Browse files
Merge pull request #56 from LewisProjects/development
1.9 minor fixes and yt uploads
2 parents be36da5 + 389f38c commit 03eb437

File tree

9 files changed

+73
-16
lines changed

9 files changed

+73
-16
lines changed

cogs/AI.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ def __init__(self, bot: OGIROID):
1313
@commands.slash_command(description="Generates ai art")
1414
async def ai_art(self, inter: disnake.ApplicationCommandInteraction, text):
1515
ETA = int(time.time() + 60)
16-
await inter.send(f"Go grab a coffee this may take a while... ETA: <t:{ETA}:R>")
16+
await inter.send(f"Go grab a coffee this may take a while... ETA: <t:{ETA}:R>", ephemeral=True)
1717
response = await self.bot.session.post("https://backend.craiyon.com/generate", json={"prompt": text})
1818
r = await response.json()
19-
images = r["images"]
20-
for i in images:
21-
image = BytesIO(base64.decodebytes(i.encode("utf-8")))
22-
await inter.delete_original_response()
23-
return await inter.send("Have fun...", file=disnake.File(image, "image.png"), ephemeral=True)
19+
raw_images = r["images"]
20+
images = [disnake.File(BytesIO(base64.decodebytes(i.encode("utf-8"))), "image.png") for i in raw_images]
21+
22+
await inter.edit_original_response(files=images, content="Here you go!")
2423

2524

2625
def setup(bot):

cogs/Fun.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ async def spotifyinfo(self, inter: ApplicationCommandInteraction, user: Member):
8686
await inter.send(embed=e)
8787

8888
@commands.slash_command(name="poll", description="Make a Poll enter a question atleast 2 options and upto 6 options.")
89-
@commands.has_permissions(manage_messages=True)
89+
@commands.cooldown(1, 90, commands.BucketType.user)
90+
@commands.cooldown(1, 30, commands.BucketType.channel)
9091
async def poll(
9192
self,
9293
inter: ApplicationCommandInteraction,

cogs/Lewis.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import disnake
2+
import datetime as dt
3+
from disnake.ext import commands, tasks
4+
5+
from utils.bot import OGIROID
6+
7+
8+
class Lewis(commands.Cog, name="Lewis"):
9+
def __init__(self, bot: OGIROID):
10+
self.bot = bot
11+
self.upload_check.start()
12+
self.youtube_channel_id = "UCWI-ohtRu8eEeDj93hmUsUQ"
13+
self.youtube_channel_url = f"https://www.youtube.com/channel/{self.youtube_channel_id}"
14+
self.youtube_api_key = self.bot.config.tokens.yt_api_key
15+
self.youtube_api_url = f"https://www.googleapis.com/youtube/v3/search?part=snippet&channelId={self.youtube_channel_id}&maxResults=1&order=date&type=video&key={self.youtube_api_key}"
16+
17+
def cog_unload(self):
18+
self.upload_check.cancel()
19+
20+
@tasks.loop(minutes=30)
21+
async def upload_check(self):
22+
if self.youtube_api_key is None:
23+
print("No YouTube API key found, skipping upload check")
24+
return
25+
check_time = dt.datetime.utcnow()
26+
channel = self.bot.get_channel(self.bot.config.channels.uploads)
27+
if channel is None:
28+
return
29+
30+
response = await self.bot.session.get(self.youtube_api_url)
31+
response = await response.json()
32+
33+
video_id = response["items"][0]["id"]["videoId"]
34+
video_url = f"https://www.youtube.com/watch?v={video_id}"
35+
# Credits to Simon for the idea and part of the code
36+
37+
video_release_time = response["items"][0]["snippet"]["publishedAt"]
38+
year = video_release_time.split("-")[0]
39+
month = video_release_time.split("-")[1]
40+
day = video_release_time.split("-")[2].split("T")[0]
41+
hour = video_release_time.split("T")[1].split(":")[0]
42+
minute = video_release_time.split("T")[1].split(":")[1]
43+
second = video_release_time.split("T")[1].split(":")[2].split("Z")[0]
44+
time = dt.datetime(int(year), int(month), int(day), int(hour), int(minute), int(second))
45+
if check_time - time < dt.timedelta(minutes=30):
46+
return await channel.send(f"Hey, Lewis posted a new video! <@&{self.bot.config.roles.yt_announcements}>\n{video_url}")
47+
else:
48+
return
49+
50+
51+
def setup(bot):
52+
bot.add_cog(Lewis(bot))

cogs/Staff.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ async def on_ready(self):
7676
async def ban(
7777
self,
7878
inter: ApplicationCommandInteraction,
79-
member: disnake.Member,
79+
user: disnake.User,
8080
reason: str = None,
8181
delete_messages: int = ParamInfo(
8282
description="How many days of messages to delete.", default=0, choices=[0, 1, 2, 3, 4, 5, 6, 7]
8383
),
8484
):
8585
"""Bans a user from the server."""
86-
await inter.guild.ban(user=member, reason=reason, clean_history_duration=dt.timedelta(days=delete_messages))
86+
await inter.guild.ban(user=user, reason=reason, clean_history_duration=dt.timedelta(days=delete_messages))
8787
await sucEmb(inter, "User has been banned successfully!")
8888

8989
@commands.slash_command(name="softban", description="Softbans a user from the server.")
@@ -92,14 +92,14 @@ async def ban(
9292
async def softban(
9393
self,
9494
inter: ApplicationCommandInteraction,
95-
member: disnake.Member,
95+
user: disnake.User,
9696
reason: str = None,
9797
):
9898
"""Bans a user from the server."""
99-
await inter.guild.ban(user=member, reason=reason or "softban", clean_history_duration=dt.timedelta(days=7))
99+
await inter.guild.ban(user=user, reason=reason or "softban", clean_history_duration=dt.timedelta(days=7))
100100
await sucEmb(inter, "User has been softbanned successfully!")
101101
await asyncio.sleep(5)
102-
await inter.guild.unban(user=member, reason="softban unban")
102+
await inter.guild.unban(user=user, reason="softban unban")
103103

104104
@commands.slash_command(name="kick", description="Kicks a user from the server.")
105105
@commands.has_permissions(kick_members=True)

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
aiohttp==3.8.1
22
aiosqlite==0.17.0
33
akinator==1.0.2
4-
disnake==2.6.0
4+
disnake==2.7.0
55
parsedatetime==2.6
66
python-dotenv==0.21.0
77
requests==2.28.1

secrets.env.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
TOKEN=
22
SRA_API_TOKEN=
33
OPEN_WEATHER_MAP_API_KEY=
4+
YT_API_KEY=
45
POSTGRES_USER=
56
POSTGRES_PASSWORD=
67
POSTGRES_HOST=

utils/CONSTANTS.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from dataclasses import dataclass
44

5-
__VERSION__ = "1.8.6"
5+
__VERSION__ = "1.9"
66

77
from typing import Final
88

@@ -26,6 +26,7 @@ class Channels:
2626
general: int = 897666935708352587
2727
roles: int = 933102052173828136
2828
rules: int = 905182869410955355
29+
uploads: int = 1033712950252408884
2930

3031
@classmethod
3132
def dev(cls):
@@ -44,6 +45,7 @@ def dev(cls):
4445
cls.general: int = 985729550732394536
4546
cls.roles: int = 1013853473172893837
4647
cls.rules: int = 1013853473172893837
48+
cls.uploads: int = 1013853473172893837
4749
return cls
4850

4951

@@ -62,10 +64,12 @@ def dev(cls):
6264
@dataclass
6365
class Roles:
6466
staff: int = 980700205328502794
67+
yt_announcements: int = 1010237178036633670
6568

6669
@classmethod
6770
def dev(cls):
6871
cls.staff: int = 985943266115584010
72+
cls.yt_announcements: int = 1007202835957563412
6973
return cls
7074

7175

utils/bot.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import disnake
99
from disnake import ApplicationCommandInteraction, OptionType
1010
from disnake.ext import commands
11-
from disnake.ext.commands import when_mentioned_or
1211

1312
from utils.CONSTANTS import __VERSION__
1413
from utils.DBhandlers import BlacklistHandler
@@ -27,7 +26,7 @@ def __init__(self, *args, **kwargs):
2726

2827
super().__init__(
2928
intents=disnake.Intents.all(),
30-
sync_commands_debug=True,
29+
command_sync_flags=commands.CommandSyncFlags(sync_commands_debug=True),
3130
*args,
3231
**kwargs,
3332
)

utils/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class Tokens:
1010
SRA: str = os.getenv("SRA_API_KEY")
1111
bot: str = os.getenv("TOKEN")
1212
weathermap: str = os.getenv("OPEN_WEATHER_MAP_API_KEY")
13+
yt_api_key: str = os.getenv("YT_API_KEY")
1314

1415

1516
@dataclass

0 commit comments

Comments
 (0)