Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
worker: python ./src/main.py
worker: python ./main.py
3 changes: 2 additions & 1 deletion data/prefixes.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"785867687536230420": "$dex",
"947421517317304361": "$dex",
"802197877039956008": "$dex",
"761902999207280690": "$dex"
"761902999207280690": "$dex",
"948280503952347166": "$dex"
}
3 changes: 2 additions & 1 deletion data/tag_messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"785867687536230420": "off",
"947421517317304361": "on",
"802197877039956008": "off",
"761902999207280690": "off"
"761902999207280690": "off",
"948280503952347166": "off"
}
4 changes: 4 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from src import Bot

if __name__ == '__main__':
Bot().run()
1 change: 1 addition & 0 deletions src/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .bot import Bot
Binary file added src/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file added src/__pycache__/bot.cpython-39.pyc
Binary file not shown.
148 changes: 148 additions & 0 deletions src/bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import discord
import json
import os
import datetime
from discord.ext import commands


class Bot(commands.Bot):

CC_LOGO_URL = 'https://avatars.githubusercontent.com/u/63065397?v=4'
INTRO_IMG_URL = 'https://user-images.githubusercontent.com/63065397/156466208-ffb6db84-f0c0-4860-ab6d-48ad0f2cd5f7.png'
EXHAUSTED_FACE = 'https://user-images.githubusercontent.com/63065397/156922064-95c73c2a-b6cb-402e-b24b-d79fe7bf520a.png'
DEX_YELLOW = 0x8e38ce
REPOSITORY_URL = 'https://github.com/code-chaser/dex/'

def __init__(self, *args, **kwargs):
super().__init__(
command_prefix=self.get_prefix,
intents=discord.Intents.all(),
activity=discord.Activity(
type=discord.ActivityType.listening,
name="Stop WW3!",
large_image_url=self.EXHAUSTED_FACE,
small_image_url=self.EXHAUSTED_FACE,
start=datetime.datetime(2022, 2, 24),
),
)

for file in os.listdir('./src/cogs'):
if file.endswith('.py'):
self.load_extension(f'src.cogs.{file[:-3]}')

async def get_prefix(self, message):
with open('./data/prefixes.json', 'r') as pref:
prefixes = json.load(pref)
print(prefixes[str(message.guild.id)]+"\n\n")
return prefixes[str(message.guild.id)] + ' '

def run(self) -> None:
super().run(os.getenv('BOT_TOKEN'))

async def on_ready(self) -> None:
print('Logged in as {0.user}'.format(self))

async def on_guild_join(self, guild) -> None:
with open('./data/prefixes.json', 'r') as pref:
prefixes = json.load(pref)
prefixes[str(guild.id)] = '$dex'
with open('./data/prefixes.json', 'w') as pref:
json.dump(prefixes, pref, indent=4)
with open('./data/tag_messages.json', 'r') as tag_:
tag_messages = json.load(tag_)
tag_messages[str(guild.id)] = 'on'
with open('./data/tag_messages.json', 'w') as tag_:
json.dump(tag_messages, tag_, indent=4)
for channel in guild.text_channels:
if channel.permissions_for(guild.me).send_messages:
general = channel
if general is not None:
await general.send(embed=self.intro_msg_embed(guild))

async def on_guild_remove(self, guild) -> None:
with open('./data/prefixes.json', 'r') as pref:
prefixes = json.load(pref)
if str(guild.id) in prefixes.keys():
prefixes.pop(str(guild.id))
with open('./data/prefixes.json', 'w') as pref:
json.dump(prefixes, pref, indent=4)
with open('./data/tag_messages.json', 'r') as tag_:
tag_messages = json.load(tag_)
if str(guild.id) in tag_messages.keys():
tag_messages.pop(str(guild.id))
with open('./data/tag_messages.json', 'w') as tag_:
json.dump(tag_messages, tag_, indent=4)

async def on_message(self, message) -> None:
await self.process_commands(message)
with open('./data/tag_messages.json', 'r') as tag_:
tag_messages = json.load(tag_)
if tag_messages[str(message.guild.id)] == 'off':
return
target = message.author
if target == self.user or target.bot:
return
embed = discord.Embed(
title='Message Tagged',
colour=target.colour,
timestamp=datetime.datetime.utcnow(),
)
embed.set_footer(
text=''.join('`<prefix> tags off` -to turn this off'),
)
embed.add_field(name='Message', value=message.content, inline=False)
embed.add_field(name='Author', value=target.mention, inline=True)
embed.set_thumbnail(url=target.avatar_url)
await message.channel.send(embed=embed)

async def on_command_error(self, ctx, error) -> None:
embed = discord.Embed(
title='Status',
colour=0xff0000,
timestamp=datetime.datetime.utcnow(),
)
if isinstance(error, commands.MissingPermissions):
n = 'Error'
v = 'Missing Permissions'
elif isinstance(error, commands.MissingRequiredArgument):
n = 'Error'
v = 'Missing required arguements'
elif isinstance(error, commands.MemberNotFound):
n = 'Error'
v = "Requested member not found or Dex doesn't have access to them"
elif isinstance(error, commands.BotMissingPermissions):
n = 'Error'
v = 'Missing Permissions'
elif isinstance(error, commands.CommandNotFound):
n = 'Error'
v = 'Invalid Command'
else:
raise error
embed.add_field(name=n, value=v, inline=False)
await ctx.send(embed=embed)

def intro_msg_embed(self, guild):
description = ''
description = description.join(
'\nThanks for adding me to ' + guild.name + '!')
description = description.join('\nUse `$dex help` to get started!')
description = description.join(
'\nVisit: '.join(self.REPOSITORY_URL))
embed = discord.Embed(
title='**GREETINGS!**',
description=description,
color=self.DEX_YELLOW,
timestamp=datetime.datetime.utcnow(),
)
embed.set_image(url=self.INTRO_IMG_URL)
embed.set_author(
name='dex',
url=self.REPOSITORY_URL,
icon_url=self.user.avatar_url,
)
embed.set_footer(
text='made by codechaser',
icon_url=self.CC_LOGO_URL,
)
embed.set_thumbnail(url=guild.icon_url)
return embed
Binary file added src/cogs/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file added src/cogs/__pycache__/codeforces.cpython-39.pyc
Binary file not shown.
Binary file removed src/cogs/__pycache__/fun.cpython-38.pyc
Binary file not shown.
Binary file modified src/cogs/__pycache__/fun.cpython-39.pyc
Binary file not shown.
Binary file removed src/cogs/__pycache__/info.cpython-38.pyc
Binary file not shown.
Binary file modified src/cogs/__pycache__/info.cpython-39.pyc
Binary file not shown.
Binary file removed src/cogs/__pycache__/modset.cpython-38.pyc
Binary file not shown.
Binary file modified src/cogs/__pycache__/modset.cpython-39.pyc
Binary file not shown.
Binary file removed src/cogs/__pycache__/music.cpython-38.pyc
Binary file not shown.
Binary file modified src/cogs/__pycache__/music.cpython-39.pyc
Binary file not shown.
Binary file removed src/cogs/__pycache__/report.cpython-38.pyc
Binary file not shown.
Binary file modified src/cogs/__pycache__/report.cpython-39.pyc
Binary file not shown.
61 changes: 30 additions & 31 deletions src/cogs/fun.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import discord
import requests
import json
import os
from typing import Optional
from datetime import datetime
from discord import Embed
from discord.ext.commands import Cog
from discord.ext.commands import command
import datetime
import typing
from discord.ext import commands


class Fun(Cog):
class Fun(commands.Cog):
def __init__(self, bot):
self.bot = bot

Expand All @@ -18,11 +16,11 @@ def get_iquote(self):
quote = "\"" + quote_json[0]['q'] + "\" -" + quote_json[0]['a']
return (quote_json)

@command(name="inspire", aliases=["iquote"], help="sends a random inspirational quote")
@commands.command(name="inspire", aliases=["iquote"], help="sends a random inspirational quote")
async def send_iquote(self, ctx):
embed = Embed(title="Inspirational Quote",
embed = discord.Embed(title="Inspirational Quote",
colour=ctx.author.colour,
timestamp=datetime.utcnow())
timestamp=datetime.datetime.utcnow())
iquote = self.get_iquote()
embed.add_field(name="Quote", value=iquote[0]['q'], inline=False)
embed.add_field(name="Author", value=iquote[0]['a'], inline=False)
Expand All @@ -34,12 +32,12 @@ def get_nasa(self):
response_json = json.loads(response.text)
return response_json

@command(name="astropic", aliases=["astropicotd", "nasapic", "nasapicotd"], help="sends astronomy pic of the day from NASA")
@commands.command(name="apod", aliases=["napod", "astropic", "astropicotd"], help="sends astronomy pic of the day from NASA")
async def send_nasa_pic_otd(self, ctx):
embed = Embed(title="NASA",
embed = discord.Embed(title="NASA",
description="Picture of the day",
colour=0x0B3D91,
timestamp=datetime.utcnow())
timestamp=datetime.datetime.utcnow())
embed.set_thumbnail(
url="https://user-images.githubusercontent.com/63065397/156291255-4af80382-836c-4801-8b4f-47da33ea36c5.png")
embed.set_footer(text="updated daily at 05:00:00 UTC [00:00:00 ET]")
Expand All @@ -55,7 +53,7 @@ def get_covid19_details(self):
response_json = json.loads(response.text)
return response_json

@command(name="covid19", help="sends COVID-19 stats of the given country (global stats if country == null)")
@commands.command(name="covid19", help="sends COVID-19 stats of the given country (global stats if country == null)")
async def covid19_data(self, ctx, *args):
countr = ""
for arg in args:
Expand All @@ -68,11 +66,11 @@ async def covid19_data(self, ctx, *args):
if country:
for k in stats["Countries"]:
if ((k["CountryCode"]).lower() == country.lower()) or ((k["Country"]).lower() == country.lower()):
embed = Embed(
embed = discord.Embed(
title=(k["Country"]).title(),
description="COVID-19 Statistics",
colour=0xff0000,
timestamp=datetime.utcnow()
timestamp=datetime.datetime.utcnow()
)
flag_url = "https://flagcdn.com/w640/" + \
str(k["CountryCode"]).lower() + ".jpg"
Expand All @@ -94,14 +92,15 @@ async def covid19_data(self, ctx, *args):
found = True
else:
k = stats["Global"]
embed = Embed(
embed = discord.Embed(
title="Global",
description="COVID-19 Statistics",
colour=0xff0000,
timestamp=datetime.utcnow()
timestamp=datetime.datetime.utcnow()
)
embed.set_thumbnail(
url="https://user-images.githubusercontent.com/63065397/156144079-6f90504d-ad48-4f2e-bec5-bae31cebd858.png")
url="https://user-images.githubusercontent.com/63065397/156144079-6f90504d-ad48-4f2e-bec5-bae31cebd858.png"
)
fields = [
("New Confirmed Cases", k["NewConfirmed"], True),
("Total Confirmed Cases", k["TotalConfirmed"], True),
Expand All @@ -115,7 +114,7 @@ async def covid19_data(self, ctx, *args):
await ctx.send(embed=embed)
found = True
if not found:
embed = Embed(
embed = discord.Embed(
title="Error",
description="Country Not Found",
colour=0xff0000
Expand All @@ -129,11 +128,11 @@ def get_meme(self):
response_json = json.loads(response.text)
return response_json

@command(name="meme", aliases=["hehe"], help="sends a random meme")
@commands.command(name="meme", aliases=["hehe"], help="sends a random meme")
async def send_meme(self, ctx):
embed = Embed(title="MEME",
embed = discord.Embed(title="MEME",
colour=0xffee00,
timestamp=datetime.utcnow())
timestamp=datetime.datetime.utcnow())
meme = self.get_meme()
embed.add_field(name="Post Link", value=meme["postLink"], inline=True)
embed.add_field(name="Author", value=meme["author"], inline=True)
Expand All @@ -152,25 +151,25 @@ def get_subreddit(self, subreddit):
response_json = json.loads(response.text)
return response_json

@command(name="reddit", aliases=["subreddit"], help="shows top headlines of the given subreddit")
async def send_subreddit(self, ctx, subreddit, number: Optional[int]):
@commands.command(name="reddit", aliases=["subreddit"], help="shows top headlines of the given subreddit")
async def send_subreddit(self, ctx, subreddit, number: typing.Optional[int]):
data = self.get_subreddit(subreddit)
if ('message' in data.keys()):
if data['message'] == "Not Found":
embed = Embed(
embed = discord.Embed(
title="Status",
colour=0xff0000,
timestamp=datetime.utcnow()
timestamp=datetime.datetime.utcnow()
)
embed.add_field(name="Error", value="Not Found", inline=True)
embed.set_footer(text="given subreddit: "+subreddit)
await ctx.send(embed=embed)
return
embed = Embed(
embed = discord.Embed(
title="Error",
description="API Request Fail",
colour=0xff0000,
timestamp=datetime.utcnow()
timestamp=datetime.datetime.utcnow()
)
for key_i in data.keys():
if key_i != 'message' and key_i != 'error':
Expand All @@ -185,8 +184,8 @@ async def send_subreddit(self, ctx, subreddit, number: Optional[int]):
embed.set_footer(text="given subreddit: "+subreddit)
await ctx.send(embed=embed)
else:
embed = Embed(title=str("/r/"+subreddit),
colour=0xff5700, timestamp=datetime.utcnow())
embed = discord.Embed(title=str("/r/"+subreddit),
colour=0xff5700, timestamp=datetime.datetime.utcnow())
embed.set_thumbnail(
url="https://user-images.githubusercontent.com/63065397/156344382-821872f3-b6e3-46e7-b925-b5f1a0821da8.png")
i = 1
Expand Down
Loading