Skip to content

Commit 07160b6

Browse files
authored
v1.1 update
New Features: - Implemented Lyrics - Some bugfixes in ./src/cogs/music.py
2 parents ed99b80 + 39b8c9e commit 07160b6

25 files changed

Lines changed: 521 additions & 421 deletions

Procfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
worker: python ./src/main.py
1+
worker: python ./main.py

data/prefixes.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
"785867687536230420": "$dex",
55
"947421517317304361": "$dex",
66
"802197877039956008": "$dex",
7-
"761902999207280690": "$dex"
7+
"761902999207280690": "$dex",
8+
"948280503952347166": "$dex"
89
}

data/tag_messages.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
"785867687536230420": "off",
55
"947421517317304361": "on",
66
"802197877039956008": "off",
7-
"761902999207280690": "off"
7+
"761902999207280690": "off",
8+
"948280503952347166": "off"
89
}

main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from src import Bot
2+
3+
if __name__ == '__main__':
4+
Bot().run()

src/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .bot import Bot
158 Bytes
Binary file not shown.

src/__pycache__/bot.cpython-39.pyc

5.18 KB
Binary file not shown.

src/bot.py

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
import discord
2+
import json
3+
import os
4+
import datetime
5+
from discord.ext import commands
6+
7+
8+
class Bot(commands.Bot):
9+
10+
CC_LOGO_URL = 'https://avatars.githubusercontent.com/u/63065397?v=4'
11+
INTRO_IMG_URL = 'https://user-images.githubusercontent.com/63065397/156466208-ffb6db84-f0c0-4860-ab6d-48ad0f2cd5f7.png'
12+
EXHAUSTED_FACE = 'https://user-images.githubusercontent.com/63065397/156922064-95c73c2a-b6cb-402e-b24b-d79fe7bf520a.png'
13+
DEX_YELLOW = 0x8e38ce
14+
REPOSITORY_URL = 'https://github.com/code-chaser/dex/'
15+
16+
def __init__(self, *args, **kwargs):
17+
super().__init__(
18+
command_prefix=self.get_prefix,
19+
intents=discord.Intents.all(),
20+
activity=discord.Activity(
21+
type=discord.ActivityType.listening,
22+
name="Stop WW3!",
23+
large_image_url=self.EXHAUSTED_FACE,
24+
small_image_url=self.EXHAUSTED_FACE,
25+
start=datetime.datetime(2022, 2, 24),
26+
),
27+
)
28+
29+
for file in os.listdir('./src/cogs'):
30+
if file.endswith('.py'):
31+
self.load_extension(f'src.cogs.{file[:-3]}')
32+
33+
async def get_prefix(self, message):
34+
with open('./data/prefixes.json', 'r') as pref:
35+
prefixes = json.load(pref)
36+
print(prefixes[str(message.guild.id)]+"\n\n")
37+
return prefixes[str(message.guild.id)] + ' '
38+
39+
def run(self) -> None:
40+
super().run(os.getenv('BOT_TOKEN'))
41+
42+
async def on_ready(self) -> None:
43+
print('Logged in as {0.user}'.format(self))
44+
45+
async def on_guild_join(self, guild) -> None:
46+
with open('./data/prefixes.json', 'r') as pref:
47+
prefixes = json.load(pref)
48+
prefixes[str(guild.id)] = '$dex'
49+
with open('./data/prefixes.json', 'w') as pref:
50+
json.dump(prefixes, pref, indent=4)
51+
with open('./data/tag_messages.json', 'r') as tag_:
52+
tag_messages = json.load(tag_)
53+
tag_messages[str(guild.id)] = 'on'
54+
with open('./data/tag_messages.json', 'w') as tag_:
55+
json.dump(tag_messages, tag_, indent=4)
56+
for channel in guild.text_channels:
57+
if channel.permissions_for(guild.me).send_messages:
58+
general = channel
59+
if general is not None:
60+
await general.send(embed=self.intro_msg_embed(guild))
61+
62+
async def on_guild_remove(self, guild) -> None:
63+
with open('./data/prefixes.json', 'r') as pref:
64+
prefixes = json.load(pref)
65+
if str(guild.id) in prefixes.keys():
66+
prefixes.pop(str(guild.id))
67+
with open('./data/prefixes.json', 'w') as pref:
68+
json.dump(prefixes, pref, indent=4)
69+
with open('./data/tag_messages.json', 'r') as tag_:
70+
tag_messages = json.load(tag_)
71+
if str(guild.id) in tag_messages.keys():
72+
tag_messages.pop(str(guild.id))
73+
with open('./data/tag_messages.json', 'w') as tag_:
74+
json.dump(tag_messages, tag_, indent=4)
75+
76+
async def on_message(self, message) -> None:
77+
await self.process_commands(message)
78+
with open('./data/tag_messages.json', 'r') as tag_:
79+
tag_messages = json.load(tag_)
80+
if tag_messages[str(message.guild.id)] == 'off':
81+
return
82+
target = message.author
83+
if target == self.user or target.bot:
84+
return
85+
embed = discord.Embed(
86+
title='Message Tagged',
87+
colour=target.colour,
88+
timestamp=datetime.datetime.utcnow(),
89+
)
90+
embed.set_footer(
91+
text=''.join('`<prefix> tags off` -to turn this off'),
92+
)
93+
embed.add_field(name='Message', value=message.content, inline=False)
94+
embed.add_field(name='Author', value=target.mention, inline=True)
95+
embed.set_thumbnail(url=target.avatar_url)
96+
await message.channel.send(embed=embed)
97+
98+
async def on_command_error(self, ctx, error) -> None:
99+
embed = discord.Embed(
100+
title='Status',
101+
colour=0xff0000,
102+
timestamp=datetime.datetime.utcnow(),
103+
)
104+
if isinstance(error, commands.MissingPermissions):
105+
n = 'Error'
106+
v = 'Missing Permissions'
107+
elif isinstance(error, commands.MissingRequiredArgument):
108+
n = 'Error'
109+
v = 'Missing required arguements'
110+
elif isinstance(error, commands.MemberNotFound):
111+
n = 'Error'
112+
v = "Requested member not found or Dex doesn't have access to them"
113+
elif isinstance(error, commands.BotMissingPermissions):
114+
n = 'Error'
115+
v = 'Missing Permissions'
116+
elif isinstance(error, commands.CommandNotFound):
117+
n = 'Error'
118+
v = 'Invalid Command'
119+
else:
120+
raise error
121+
embed.add_field(name=n, value=v, inline=False)
122+
await ctx.send(embed=embed)
123+
124+
def intro_msg_embed(self, guild):
125+
description = ''
126+
description = description.join(
127+
'\nThanks for adding me to ' + guild.name + '!')
128+
description = description.join('\nUse `$dex help` to get started!')
129+
description = description.join(
130+
'\nVisit: '.join(self.REPOSITORY_URL))
131+
embed = discord.Embed(
132+
title='**GREETINGS!**',
133+
description=description,
134+
color=self.DEX_YELLOW,
135+
timestamp=datetime.datetime.utcnow(),
136+
)
137+
embed.set_image(url=self.INTRO_IMG_URL)
138+
embed.set_author(
139+
name='dex',
140+
url=self.REPOSITORY_URL,
141+
icon_url=self.user.avatar_url,
142+
)
143+
embed.set_footer(
144+
text='made by codechaser',
145+
icon_url=self.CC_LOGO_URL,
146+
)
147+
embed.set_thumbnail(url=guild.icon_url)
148+
return embed
132 Bytes
Binary file not shown.
1.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)