Skip to content

Commit

Permalink
[v.0.1.0] Merge dev into master
Browse files Browse the repository at this point in the history
Merged dev into master.

This concludes the development of the !help window.

v.0.1.0 is officially released.
  • Loading branch information
ItsShunya authored Oct 30, 2020
2 parents 5e88d4e + 81cc38b commit 4f83159
Show file tree
Hide file tree
Showing 21 changed files with 684 additions and 781 deletions.
12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,14 @@ __pycache__/

# Logging
*.log
*.gz
*.gz
*.1
*.2
*.3
*.4
*.5
*.6
*.7
*.8
*.9
*.10
28 changes: 17 additions & 11 deletions ShunyaBOT.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import dotenv
import discord

from dotenv import load_dotenv, find_dotenv
from dotenv import load_dotenv
from datetime import datetime
from discord.ext import commands
from utilities.embeds import embed_error, set_style
Expand All @@ -21,24 +21,29 @@
print('[ERROR] Python 3.6 or + is required.')
exit()

# Configuration parameters set up.
dotenv_path = os.path.join(f'{os.path.dirname(__file__)}/config', '.env')
# Configuration parameters set-up.
dotenv_path = os.path.join(f'{os.path.dirname(sys.argv[0])}/config', '.env')
load_dotenv(dotenv_path)
token = os.getenv('DISCORD_TOKEN')
database_path = os.path.join(f'{os.path.dirname(__file__)}/config', 'database.sqlite')
database_path = os.path.join(f'{os.path.dirname(sys.argv[0])}/config', 'database.sqlite')

@contextlib.contextmanager # No need to define __enter__() and __exit__() methods.
def logger():
'''Creates different loggers to keep track of everything.'''

logs = {'discord': None, 'wavelink': None, 'bot': None}

if not os.path.exists('logs/lavalink'): # This one is for the Lavalink server
os.makedirs('logs/lavalink')

for log_name in logs.keys():
log = logging.getLogger(log_name)
# We only need one handler for all the logs.
handler = logging.handlers.RotatingFileHandler(filename=f'logs/{log_name}.log', mode='w', backupCount=5, encoding='utf-8', maxBytes=2**22)
if not os.path.exists(f'logs/{log_name}'):
os.makedirs(f'logs/{log_name}')
handler = logging.handlers.RotatingFileHandler(filename=f'logs/{log_name}/{log_name}.log', mode='w', backupCount=5, encoding='utf-8', maxBytes=2**22)
handler.setFormatter(logging.Formatter('%(asctime)s %(name)s: %(levelname)s: %(message)s', datefmt='%d/%m/%Y %H:%M:%S'))
if os.path.isfile(f'logs/{log_name}.log'):
if os.path.isfile(f'logs/{log_name}/{log_name}.log'):
handler.doRollover()
log.addHandler(handler)

Expand Down Expand Up @@ -72,11 +77,12 @@ def get_prefix(bot, message):
# If we are in a guild, we allow for the user to mention us or use any of the prefixes in our list.
return commands.when_mentioned_or(*prefixes)(bot, message)

description = '''Shuwy bot implements functions for moderation, music and members.'''
bot = commands.Bot(command_prefix=get_prefix, owner_id=125345019199488000, case_insensitive=True, description=description)
bot.remove_command('help')
intents = discord.Intents.all()

description = '''Shuwy is a bot written by `Shunya#1624`. It implements basic moderation functions, automation and music.'''
bot = commands.Bot(command_prefix = get_prefix, owner_id = 125345019199488000, case_insensitive = True, description = description, intents = intents)

bot.version = '0.0.6'
bot.version = '0.0.7'
bot.color = 0xebb145
bot.log =logging.getLogger('bot')

Expand Down Expand Up @@ -144,7 +150,7 @@ async def on_ready():
print(f'• ID: {bot.user.id}')
print(f'• Shuwy version: {bot.version}')
print(f'• Discord.py version: {discord.__version__}')
print(f'• Python version: {platform.__version__}')
print(f'• Python version: {platform.python_version()}')
print('-------------------------------')

# TO-DO: Change the following line to not include it in the on_ready event.
Expand Down
1 change: 1 addition & 0 deletions cogs/Errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class ErrorCog(commands.Cog, name='Error'):

def __init__(self, bot):
self.bot = bot
self.hidden = True

@commands.Cog.listener()
async def on_command_error(self, ctx, error):
Expand Down
4 changes: 2 additions & 2 deletions cogs/Fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ def __init__(self, bot):
@commands.command()
async def ping(self, ctx):
'''Ping-Pong.'''
embed = discord.Embed(description='Pong!', color=0xebb145)
embed = discord.Embed(description='Pong!', color=discord.Colour.purple())
await ctx.send(embed=set_style(embed))

@commands.command(name='coolbot', aliases=['cool', 'dope', 'nice'])
async def cool_bot(self, ctx):
'''Is the bot cool?'''
embed = discord.Embed(color=0xebb145, description='This bot is cool. :)')
embed = discord.Embed(color=discord.Colour.purple(), description='This bot is cool. :)')
await ctx.send(embed=set_style(embed))

def setup(bot):
Expand Down
1 change: 1 addition & 0 deletions cogs/Logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class LogsCog(commands.Cog, name='Logs'):

def __init__(self, bot):
self.bot = bot
self.hidden = True

def setup(bot):
bot.add_cog(LogsCog(bot))
Expand Down
4 changes: 2 additions & 2 deletions cogs/Math.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ def __init__(self, bot):

@commands.command(name='add', aliases=['plus'])
async def do_addition(self, ctx, first: int, second: int):
'''A simple command which does addition on two integer values.'''
'''A simple command which does addition on two values.'''

total = first + second
embed = discord.Embed(title=f'Hello, @**{ctx.author.name}**!', description=f'The sum of **{first}** and **{second}** is **{total}**.', color=0xebb145)
embed = discord.Embed(title=f'Hello, @**{ctx.author.name}**!', description=f'The sum of **{first}** and **{second}** is **{total}**.', color=discord.Colour.purple())
await ctx.send(embed=set_style(embed))


Expand Down
73 changes: 41 additions & 32 deletions cogs/Members.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,32 @@ def __init__(self, bot):
self.bot = bot

@commands.command(name='joined', aliases=['unido', 'entered'])
@commands.guild_only()
async def joined(self, ctx, *, member: discord.Member=None):
'''Says when a member joined.
'''Says when a member joined the server.
Keyword arguments:
member -- member object that we want to check '''

if member is None:
member = ctx.author
embed = discord.Embed(color=0xebb145, description=f'{member.display_name} joined on {member.joined_at}')
embed = discord.Embed(color=discord.Colour.purple(), description=f'{member.display_name} joined on {member.joined_at}')
await ctx.send(embed=set_style(embed))

@commands.command(name='top_role', aliases=['toprole', 'top_rol', 'toprol'])
@commands.guild_only()
async def show_toprole(self, ctx, *, member: discord.Member=None):
'''Simple command which shows the members Top Role.
'''Shows the members most important role.
Keyword arguments:
member -- member object that we want to check '''

if member is None:
member = ctx.author
embed = discord.Embed(color=0xebb145, description=f'The top role for {member.display_name} is {member.top_role.name}')
embed = discord.Embed(color=discord.Colour.purple(), description=f'The top role for {member.display_name} is {member.top_role.name}')
await ctx.send(embed=set_style(embed))

@commands.command(name='perms', aliases=['perms_for', 'permissions'])
@commands.guild_only()
async def check_permissions(self, ctx, *, member: discord.Member=None):
'''A simple command which checks a members Guild Permissions.
'''A simple command which checks a members permissions.
If member is not provided, the author will be checked.
Keyword arguments:
Expand All @@ -54,25 +51,24 @@ async def check_permissions(self, ctx, *, member: discord.Member=None):
# Here we check if the value of each permission is True.
perms = '\n'.join(perm for perm, value in member.guild_permissions if value)
# And to make it look nice, we wrap it in an Embed.
embed = discord.Embed(title='Permissions for:', description=ctx.guild.name, colour=0xebb145)
embed = discord.Embed(title='Permissions for:', description=ctx.guild.name, color=discord.Colour.purple())
embed.set_author(icon_url=member.avatar_url, name=str(member))
# \uFEFF is a Zero-Width Space, which basically allows us to have an empty field name.
embed.add_field(name='\uFEFF', value=perms)
await ctx.send(content=None, embed=set_style(embed))

@commands.group(invoke_without_commands=True)
@commands.guild_only()
async def welcome(self, ctx):
'''Command to set the preferences for the welcome channel/message/role.
'''Sets the preferences for the welcome channel/message/role.
Needs to be used together with one of its subcommands.'''

if ctx.invoked_subcommand is None:
embed = discord.Embed(color=0xebb145, title='Available Commands:', description='welcome channel <#channel>\nwelcome text <message>\nwelcome role <@role>\nwelcome channel_on\nwelcome channel_off\nwelcome role_on\nwelcome role_off')
embed = discord.Embed(color=discord.Colour.purple(), title='Available Commands:', description='welcome channel <#channel>\nwelcome text <message>\nwelcome role <@role>\nwelcome channel_on\nwelcome channel_off\nwelcome role_on\nwelcome role_off')
await ctx.send(embed=set_style(embed))

@welcome.command()
async def channel(self, ctx, channel:discord.TextChannel):
'''Subcommand for "welcome" function to set the welcome channel.
'''Subcommand to set the welcome channel.
Keyword arguments:
channel -- channel to be used for welcome messages'''
Expand All @@ -84,7 +80,8 @@ async def channel(self, ctx, channel:discord.TextChannel):
result = cursor.fetchone()
sql = ("UPDATE database SET welcome_channel_id = ? WHERE guild_id = ?")
val = (channel.id, ctx.guild.id)
await ctx.send(f'Welcome Channel has been set to {channel.mention}')
embed = discord.Embed(color=discord.Colour.purple(), description=f'Welcome Channel has been set to {channel.mention}')
await ctx.send(embed=set_style(embed))
cursor.execute(sql, val)
database.commit()
cursor.close()
Expand All @@ -94,7 +91,7 @@ async def channel(self, ctx, channel:discord.TextChannel):

@welcome.command()
async def text(self, ctx, *, text):
'''Subcommand for "welcome" function to set the welcome message.
'''Subcommand to set the welcome message.
Keyword arguments:
text -- message to be used as welcome messages'''
Expand All @@ -107,7 +104,8 @@ async def text(self, ctx, *, text):
result = cursor.fetchone()
sql = ("UPDATE database SET welcome_msg = ? WHERE guild_id = ?")
val = (text, ctx.guild.id)
await ctx.send(f'Welcome Message has been set to `{text}`')
embed = discord.Embed(color=discord.Colour.purple(), description=f'Welcome Message has been set to `{text}`')
await ctx.send(embed=set_style(embed))
cursor.execute(sql, val)
database.commit()
cursor.close()
Expand All @@ -117,7 +115,7 @@ async def text(self, ctx, *, text):

@welcome.command()
async def role(self, ctx, role:discord.Role):
'''Subcommand for "welcome" function to set the welcome role.
'''Subcommand to set the welcome role.
Keyword arguments:
role -- role to be set to new server members'''
Expand All @@ -127,7 +125,8 @@ async def role(self, ctx, role:discord.Role):
cursor = database.cursor()
sql = ("UPDATE database SET welcome_role_id = ? WHERE guild_id = ?")
val = (role.id, ctx.guild.id)
await ctx.send(f'Welcome Role has been set to {role.mention}')
embed = discord.Embed(color=discord.Colour.purple(), description=f'Welcome Role has been set to {role.mention}')
await ctx.send(embed=set_style(embed))
cursor.execute(sql, val)
database.commit()
cursor.close()
Expand All @@ -137,56 +136,60 @@ async def role(self, ctx, role:discord.Role):

@welcome.command()
async def channel_on(self, ctx):
'''Subcommand for "welcome" function to activate the welcome message.'''
'''Subcommand to activate the welcome message.'''

database = sqlite3.connect(database_path)
cursor = database.cursor()
sql = ("UPDATE database SET welcome_channel_on = ? WHERE guild_id = ?")
val = (1, ctx.guild.id)
cursor.execute(sql, val)
await ctx.send('Welcome Channel has been activated.')
embed = discord.Embed(color=discord.Colour.purple(), description='Welcome Channel has been activated.')
await ctx.send(embed=set_style(embed))
database.commit()
cursor.close()
database.close()

@welcome.command()
async def channel_off(self, ctx):
'''Subcommand for "welcome" function to deactivate the welcome message.'''
'''Subcommand to deactivate the welcome message.'''

database = sqlite3.connect(database_path)
cursor = database.cursor()
sql = ("UPDATE database SET welcome_channel_on = ? WHERE guild_id = ?")
val = (0, ctx.guild.id)
cursor.execute(sql, val)
await ctx.send('Welcome Channel has been deactivated.')
embed = discord.Embed(color=discord.Colour.purple(), description='Welcome Channel has been deactivated.')
await ctx.send(embed=set_style(embed))
database.commit()
cursor.close()
database.close()

@welcome.command()
async def role_on(self, ctx):
'''Subcommand for "welcome" function to activate the welcome role.'''
'''Subcommand to activate the welcome role.'''

database = sqlite3.connect(database_path)
cursor = database.cursor()
sql = ("UPDATE database SET welcome_role_on = ? WHERE guild_id = ?")
val = (1, ctx.guild.id)
cursor.execute(sql, val)
await ctx.send('Welcome Role has been activated.')
embed = discord.Embed(color=discord.Colour.purple(), description='Welcome Role has been activated.')
await ctx.send(embed=set_style(embed))
database.commit()
cursor.close()
database.close()

@welcome.command()
async def role_off(self, ctx):
'''Subcommand for "welcome" function to deactivate the welcome role.'''
'''Subcommand to deactivate the welcome role.'''

database = sqlite3.connect(database_path)
cursor = database.cursor()
sql = ("UPDATE database SET welcome_role_on = ? WHERE guild_id = ?")
val = (0, ctx.guild.id)
cursor.execute(sql, val)
await ctx.send('Welcome Role has been deactivated.')
embed = discord.Embed(color=discord.Colour.purple(), description='Welcome Channel has been deactivated.')
await ctx.send(embed=set_style(embed))
database.commit()
cursor.close()
database.close()
Expand Down Expand Up @@ -251,7 +254,6 @@ async def on_member_join(self, member):
database.close()

@commands.Cog.listener()
@commands.guild_only()
async def on_raw_reaction_add(self, reaction):
'''Event that takes places when a reaction is added to a message.'''

Expand Down Expand Up @@ -282,7 +284,6 @@ async def on_raw_reaction_add(self, reaction):
database.close()

@commands.Cog.listener()
@commands.guild_only()
async def on_raw_reaction_remove(self, reaction):
'''Event that takes places when a reaction is deleted from a message.'''

Expand Down Expand Up @@ -313,7 +314,6 @@ async def on_raw_reaction_remove(self, reaction):
database.close()

@commands.command()
@commands.guild_only()
async def role_add(self, ctx, channel:discord.TextChannel, messageid, emoji, role:discord.Role):
'''Sets a role to be added to a user when he reacts to a pre-defined message with a pre-defined role.
Expand Down Expand Up @@ -348,7 +348,6 @@ async def role_add(self, ctx, channel:discord.TextChannel, messageid, emoji, rol
database.close()

@commands.command()
@commands.guild_only()
async def role_remove(self, ctx, messageid=None, emoji=None):
'''Use it after using role_add to make the bot remove the emoji and stop adding the role to the person reacting to it.
Expand All @@ -366,7 +365,7 @@ async def role_remove(self, ctx, messageid=None, emoji=None):
await ctx.send(embed=embed_error('That reaction was not found on that message.', input1=ctx))
elif str(messageid) in str(result[2]):
cursor.execute(f"DELETE FROM reaction WHERE guild_id = '{ctx.message.guild.id}' and message_id = '{messageid}' and emoji = '{emm}'")
embed = discord.Embed(description='Reaction has been removed.', color=0xffd500)
embed = discord.Embed(description='Reaction has been removed.', color=discord.Colour.purple())
await ctx.send(embed=set_style(embed))
else:
await ctx.send(embed=embed_error('That reaction was not found on that message.', input1=ctx))
Expand All @@ -375,14 +374,24 @@ async def role_remove(self, ctx, messageid=None, emoji=None):
await ctx.send(embed=embed_error('That reaction was not found on that message.', input1=ctx))
elif str(messageid) in str(result[2]):
cursor.execute(f"DELETE FROM reaction WHERE guild_id = '{ctx.message.guild.id}' and message_id = '{messageid}' and emoji = '{emoji}'")
embed = discord.Embed(description='Reaction has been removed.', color=0xffd500)
embed = discord.Embed(description='Reaction has been removed.', color=discord.Colour.purple())
await ctx.send(embed=set_style(embed))
else:
await ctx.send(embed=embed_error('That reaction was not found on that message.', input1=ctx))
database.commit()
cursor.close()
database.close()

async def cog_check(self, ctx: commands.Context):
'''Cog wide check, which disallows commands in DMs.'''

if not ctx.guild and '!help' not in ctx.message.content:
embed = discord.Embed(description='Member related commands are not available in Private Messages!', color=discord.Colour.purple())
await ctx.send(embed=set_style(embed))
return False

return True

def setup(bot):
bot.add_cog(MembersCog(bot))
message = 'Members Cog has been loaded succesfully.'
Expand Down
Loading

0 comments on commit 4f83159

Please sign in to comment.