Browse Source

Made an enumertator for the embed colours so that it is standardised and easier to manage.

tags/v1.7.0
Roxie Gibson 6 years ago
parent
commit
db77ed9692
12 changed files with 44 additions and 31 deletions
  1. +1
    -1
      Roxbot/cogs/admin.py
  2. +1
    -1
      Roxbot/cogs/customcommands.py
  3. +1
    -1
      Roxbot/cogs/fun.py
  4. +3
    -2
      Roxbot/cogs/joinleave.py
  5. +4
    -5
      Roxbot/cogs/selfassign.py
  6. +5
    -6
      Roxbot/cogs/trivia.py
  7. +6
    -3
      Roxbot/cogs/voice.py
  8. +4
    -4
      Roxbot/err_handle.py
  9. +12
    -1
      Roxbot/load_config.py
  10. +4
    -4
      Roxbot/logging.py
  11. +2
    -2
      Roxbot/settings/settings.py
  12. +1
    -1
      main.py

+ 1
- 1
Roxbot/cogs/admin.py View File

if user_id not in settings.warnings: if user_id not in settings.warnings:
return await ctx.send("This user doesn't have any warning on record.") return await ctx.send("This user doesn't have any warning on record.")


em = discord.Embed(title="Warnings for {}".format(str(user)), colour=0XDEADBF)
em = discord.Embed(title="Warnings for {}".format(str(user)), colour=roxbot.EmbedColours.pink)
em.set_thumbnail(url=user.avatar_url) em.set_thumbnail(url=user.avatar_url)
x = 1 x = 1
userlist = settings.warnings[user_id] userlist = settings.warnings[user_id]

+ 1
- 1
Roxbot/cogs/customcommands.py View File



# TODO: Sort out a way to shorten this if it goes over 2000 characters. # TODO: Sort out a way to shorten this if it goes over 2000 characters.
em = discord.Embed(title="Here is the list of Custom Commands", color=Roxbot.embedcolour)
em = discord.Embed(title="Here is the list of Custom Commands", color=Roxbot.EmbedColours.pink)
em.add_field(name="Commands that require Prefix:", value=listone, inline=False) em.add_field(name="Commands that require Prefix:", value=listone, inline=False)
em.add_field(name="Commands that don't:", value=listzero, inline=False) em.add_field(name="Commands that don't:", value=listzero, inline=False)
return await ctx.send(embed=em) return await ctx.send(embed=em)

+ 1
- 1
Roxbot/cogs/fun.py View File

endpoint = "https://frog.tips/api/1/tips/" endpoint = "https://frog.tips/api/1/tips/"
croak = await Roxbot.http.api_request(endpoint) croak = await Roxbot.http.api_request(endpoint)
tip = random.choice(croak["tips"]) tip = random.choice(croak["tips"])
embed = discord.Embed(title="Frog Tip #{}".format(tip["number"]), description=tip["tip"], colour=discord.Colour(0x4C943D))
embed = discord.Embed(title="Frog Tip #{}".format(tip["number"]), description=tip["tip"], colour=Roxbot.EmbedColours.frog_green)
embed.set_author(name="HOW TO OPERATE YOUR FROG") embed.set_author(name="HOW TO OPERATE YOUR FROG")
embed.set_footer(text="https://frog.tips") embed.set_footer(text="https://frog.tips")
return await ctx.send(embed=embed) return await ctx.send(embed=embed)

+ 3
- 2
Roxbot/cogs/joinleave.py View File

import discord import discord
import Roxbot
from Roxbot import guild_settings from Roxbot import guild_settings




em = discord.Embed( em = discord.Embed(
title="Welcome to {}!".format(member.guild), title="Welcome to {}!".format(member.guild),
description='Hey {}! Welcome to **{}**! {}'.format(member.mention, member.guild, message), description='Hey {}! Welcome to **{}**! {}'.format(member.mention, member.guild, message),
colour=0xDEADBF)
colour=Roxbot.EmbedColours.pink)
em.set_thumbnail(url=member.avatar_url) em.set_thumbnail(url=member.avatar_url)


channel = self.bot.get_channel(settings.greets["welcome-channel"]) channel = self.bot.get_channel(settings.greets["welcome-channel"])
else: else:
channel = self.bot.get_channel(channel) channel = self.bot.get_channel(channel)
return await channel.send(embed=discord.Embed( return await channel.send(embed=discord.Embed(
description="{}#{} has left or been beaned.".format(member.name, member.discriminator), colour=0xDEADBF))
description="{}#{} has left or been beaned.".format(member.name, member.discriminator), colour=Roxbot.EmbedColours.pink))




def setup(Bot): def setup(Bot):

+ 4
- 5
Roxbot/cogs/selfassign.py View File

class SelfAssign(): class SelfAssign():
def __init__(self, Bot): def __init__(self, Bot):
self.bot = Bot self.bot = Bot
self.embed_colour = Roxbot.embedcolour


@commands.command(pass_context=True) @commands.command(pass_context=True)
async def listroles(self, ctx): async def listroles(self, ctx):
""" """
settings = gs.get(ctx.guild) settings = gs.get(ctx.guild)
if not settings.self_assign["enabled"]: if not settings.self_assign["enabled"]:
embed = discord.Embed(colour=discord.Colour(self.embed_colour), description="SelfAssignable roles are not enabled on this server")
embed = discord.Embed(colour=Roxbot.EmbedColours.pink, description="SelfAssignable roles are not enabled on this server")
return await ctx.send(embed=embed) return await ctx.send(embed=embed)
roles = [] roles = []
for role in settings.self_assign["roles"]: for role in settings.self_assign["roles"]:
if role == serverrole.id: if role == serverrole.id:
roles.append("**"+serverrole.name+"**") roles.append("**"+serverrole.name+"**")
roles = '\n'.join(roles) roles = '\n'.join(roles)
embed = discord.Embed(colour=self.embed_colour, description="The self-assignable roles for this server are: \n"+roles)
embed = discord.Embed(colour=Roxbot.EmbedColours.pink, description="The self-assignable roles for this server are: \n"+roles)
return await ctx.send(embed=embed) return await ctx.send(embed=embed)


@commands.command(pass_context=True) @commands.command(pass_context=True)
raise commands.MissingRequiredArgument(Parameter("Role", False)) raise commands.MissingRequiredArgument(Parameter("Role", False))


if not settings.self_assign["enabled"]: if not settings.self_assign["enabled"]:
embed = discord.Embed(colour=discord.Colour(self.embed_colour), description="SelfAssignable roles are not enabled on this server")
embed = discord.Embed(colour=Roxbot.EmbedColours.pink, description="SelfAssignable roles are not enabled on this server")
return await ctx.send(embed=embed) return await ctx.send(embed=embed)


member = ctx.author member = ctx.author
raise commands.MissingRequiredArgument(Parameter("role", False)) raise commands.MissingRequiredArgument(Parameter("role", False))


if not settings.self_assign["enabled"]: if not settings.self_assign["enabled"]:
embed = discord.Embed(colour=discord.Colour(self.embed_colour), description="SelfAssignable roles are not enabled on this server")
embed = discord.Embed(colour=Roxbot.EmbedColours.pink, description="SelfAssignable roles are not enabled on this server")
return await ctx.send(embed=embed) return await ctx.send(embed=embed)


member = ctx.author member = ctx.author

+ 5
- 6
Roxbot/cogs/trivia.py View File

from collections import OrderedDict from collections import OrderedDict
from discord.ext import commands from discord.ext import commands


from Roxbot import http
from Roxbot import checks
from Roxbot import http, checks, EmbedColours




class Trivia: class Trivia:
self.incorrect_emoji = self.bot.get_emoji(421526796379488256) self.incorrect_emoji = self.bot.get_emoji(421526796379488256)
self.emojis = [a_emoji, b_emoji, c_emoji, d_emoji] self.emojis = [a_emoji, b_emoji, c_emoji, d_emoji]
self.games = {} self.games = {}
self.error_colour = 0x992d22
self.trivia_colour = 0x6f90f5
self.error_colour = EmbedColours.dark_red
self.trivia_colour = EmbedColours.blue


# Game Functions # Game Functions


async def trivia(self, ctx): async def trivia(self, ctx):
"""Command group for the Roxbot Trivia game.""" """Command group for the Roxbot Trivia game."""
if ctx.invoked_subcommand == self.start and ctx.channel.id not in self.games: if ctx.invoked_subcommand == self.start and ctx.channel.id not in self.games:
embed = discord.Embed(colour=0xDEADBF)
embed = discord.Embed(colour=EmbedColours.pink)
embed.set_footer(text="Roxbot Trivia uses the Open Trivia DB, made and maintained by Pixeltail Games LLC. Find out more at https://opentdb.com/") embed.set_footer(text="Roxbot Trivia uses the Open Trivia DB, made and maintained by Pixeltail Games LLC. Find out more at https://opentdb.com/")
embed.set_image(url="https://i.imgur.com/yhRVl9e.png") embed.set_image(url="https://i.imgur.com/yhRVl9e.png")
await ctx.send(embed=embed) await ctx.send(embed=embed)
embed = discord.Embed( embed = discord.Embed(
title="About Roxbot Trivia", title="About Roxbot Trivia",
description="Roxbot Trivia is a trivia game in *your* discord server. It's heavily inspired by Tower Unite's trivia game. (and even uses the same questions database!) To start, just type `{}trivia start`.".format(self.bot.command_prefix), description="Roxbot Trivia is a trivia game in *your* discord server. It's heavily inspired by Tower Unite's trivia game. (and even uses the same questions database!) To start, just type `{}trivia start`.".format(self.bot.command_prefix),
colour=0xDEADBF)
colour=EmbedColours.pink)
embed.add_field(name="How to Play", value="Once the game has started, questions will be asked and you will be given 20 seconds to answer them. To answer, react with the corrosponding emoji. Roxbot will only accept your first answer. Score is calculated by how quickly you can answer correctly, so make sure to be as quick as possible to win! Person with the most score at the end wins. Glhf!") embed.add_field(name="How to Play", value="Once the game has started, questions will be asked and you will be given 20 seconds to answer them. To answer, react with the corrosponding emoji. Roxbot will only accept your first answer. Score is calculated by how quickly you can answer correctly, so make sure to be as quick as possible to win! Person with the most score at the end wins. Glhf!")
embed.add_field(name="Can I have shorter or longer games?", value="Yes! You can change the length of the game by adding either short (5 questions) or long (15 questions) at the end of the start command. `{}trivia start short`. The default is 10 and this is the medium option.".format(self.bot.command_prefix)) embed.add_field(name="Can I have shorter or longer games?", value="Yes! You can change the length of the game by adding either short (5 questions) or long (15 questions) at the end of the start command. `{}trivia start short`. The default is 10 and this is the medium option.".format(self.bot.command_prefix))
embed.add_field(name="Can I play with friends?", value="Yes! Trivia is best with friends. How else would friendships come to their untimely demise? You can only join a game during the 20 second waiting period after a game is started. Just type `{0}trivia join` and you're in! You can leave a game at anytime (even if its just you) by doing `{0}trivia leave`. If no players are in a game, the game will end and no one will win ;-;".format(self.bot.command_prefix)) embed.add_field(name="Can I play with friends?", value="Yes! Trivia is best with friends. How else would friendships come to their untimely demise? You can only join a game during the 20 second waiting period after a game is started. Just type `{0}trivia join` and you're in! You can leave a game at anytime (even if its just you) by doing `{0}trivia leave`. If no players are in a game, the game will end and no one will win ;-;".format(self.bot.command_prefix))

+ 6
- 3
Roxbot/cogs/voice.py View File

self.queue_logic[guild.id] = None self.queue_logic[guild.id] = None


async def _queue_logic(self, ctx): async def _queue_logic(self, ctx):
# TODO: This is broke it seems.
"""Background task designed to help the bot move on to the next video in the queue""" """Background task designed to help the bot move on to the next video in the queue"""
if ctx.voice_client.source == self.now_playing[ctx.guild.id]: if ctx.voice_client.source == self.now_playing[ctx.guild.id]:
sleep_for = 0.5 sleep_for = 0.5
return video return video


def _format_duration(self, duration): def _format_duration(self, duration):
# TODO: Fix when duration returns nothing and the bot breaks here.
hours = duration // 3600 hours = duration // 3600
minutes = (duration % 3600) // 60 minutes = (duration % 3600) // 60
seconds = duration % 60 seconds = duration % 60
duration = self._format_duration(np.duration) duration = self._format_duration(np.duration)
time_played = self._format_duration(np.source.timer/1000) time_played = self._format_duration(np.source.timer/1000)


embed = discord.Embed(title=title, colour=0xDEADBF, url=np.webpage_url)
embed = discord.Embed(title=title, colour=Roxbot.EmbedColours.pink, url=np.webpage_url)
embed.description = "Uploaded by: [{0.uploader}]({0.uploader_url})\nURL: [Here]({0.webpage_url})\nDuration: {1}\nQueued by: {0.queued_by}".format(np, duration) embed.description = "Uploaded by: [{0.uploader}]({0.uploader_url})\nURL: [Here]({0.webpage_url})\nDuration: {1}\nQueued by: {0.queued_by}".format(np, duration)
embed.set_image(url=np.thumbnail_url) embed.set_image(url=np.thumbnail_url)
embed.set_footer(text="Timer: {}/{}".format(time_played, duration)) embed.set_footer(text="Timer: {}/{}".format(time_played, duration))
# Sleep because if not, queued up things will send first and probably freak out users or something # Sleep because if not, queued up things will send first and probably freak out users or something
while self.am_queuing[guild.id] is True: while self.am_queuing[guild.id] is True:
await asyncio.sleep(0.5) await asyncio.sleep(0.5)
embed = discord.Embed(description='Added "{}" to queue'.format(video.get("title")), colour=0xDEADBF)
embed = discord.Embed(description='Added "{}" to queue'.format(video.get("title")), colour=Roxbot.EmbedColours.pink)
await ctx.send(embed=embed) await ctx.send(embed=embed)


@commands.cooldown(1, 0.5, commands.BucketType.guild) @commands.cooldown(1, 0.5, commands.BucketType.guild)


@commands.command() @commands.command()
async def skip(self, ctx, option=""): async def skip(self, ctx, option=""):
# TODO: Skipping isn't cleaned properly when successful
"""Skips or votes to skip the current video. Use option "--force" if your an admin and """ """Skips or votes to skip the current video. Use option "--force" if your an admin and """
voice = guild_settings.get(ctx.guild).voice voice = guild_settings.get(ctx.guild).voice
if ctx.voice_client.is_playing(): if ctx.voice_client.is_playing():
index += 1 index += 1
if output == "": if output == "":
output = "Nothing is up next. Maybe you should add something!" output = "Nothing is up next. Maybe you should add something!"
embed = discord.Embed(title="Queue", description=output, colour=0xDEADBF)
embed = discord.Embed(title="Queue", description=output, colour=Roxbot.EmbedColours.pink)
return await ctx.send(embed=embed) return await ctx.send(embed=embed)


@Roxbot.checks.is_admin_or_mod() @Roxbot.checks.is_admin_or_mod()

+ 4
- 4
Roxbot/err_handle.py View File

import datetime import datetime
import traceback import traceback
from discord.ext import commands from discord.ext import commands
import Roxbot
from Roxbot import guild_settings from Roxbot import guild_settings




if self.dev: if self.dev:
traceback.print_exc() traceback.print_exc()
else: else:
embed = discord.Embed(title="Roxbot Error", colour=0xe74c3c) # Red
embed = discord.Embed(title="Roxbot Error", colour=Roxbot.EmbedColours.red) # Red
embed.add_field(name='Event', value=event) embed.add_field(name='Event', value=event)
embed.description = '```py\n{}\n```'.format(traceback.format_exc()) embed.description = '```py\n{}\n```'.format(traceback.format_exc())
embed.timestamp = datetime.datetime.utcnow() embed.timestamp = datetime.datetime.utcnow()


async def on_command_error(self, ctx, error): async def on_command_error(self, ctx, error):
self.owner = self.bot.get_user(self.bot.owner_id) self.owner = self.bot.get_user(self.bot.owner_id)
err_colour = 0x992d22
if self.dev: if self.dev:
raise error raise error
elif isinstance(error, commands.CommandInvokeError): elif isinstance(error, commands.CommandInvokeError):
embed = discord.Embed(title='Command Error', colour=err_colour)
embed = discord.Embed(title='Command Error', colour=Roxbot.EmbedColours.dark_red)
embed.description = str(error) embed.description = str(error)
embed.add_field(name='Server', value=ctx.guild) embed.add_field(name='Server', value=ctx.guild)
embed.add_field(name='Channel', value=ctx.channel.mention) embed.add_field(name='Channel', value=ctx.channel.mention)
embed = discord.Embed( embed = discord.Embed(
description="Placeholder embed. If you see this please message {}.".format(str(self.owner))) description="Placeholder embed. If you see this please message {}.".format(str(self.owner)))
if embed: if embed:
embed.colour = err_colour
embed.colour = Roxbot.EmbedColours.dark_red
await ctx.send(embed=embed, delete_after=8) await ctx.send(embed=embed, delete_after=8)





+ 12
- 1
Roxbot/load_config.py View File

from enum import Enum
import configparser import configparser



settings = configparser.ConfigParser() settings = configparser.ConfigParser()
settings.read("Roxbot/settings/preferences.ini") settings.read("Roxbot/settings/preferences.ini")


token = settings["Roxbot"]["Token"] token = settings["Roxbot"]["Token"]
owner = int(settings["Roxbot"]["OwnerID"]) owner = int(settings["Roxbot"]["OwnerID"])
tat_token = settings["Roxbot"]["Tatsumaki_Token"] tat_token = settings["Roxbot"]["Tatsumaki_Token"]
embedcolour = 0xDEADBF


class EmbedColours(Enum):
pink = 0xDEADBF
yellow = 0xFDDF86
blue = 0x6F90F5
frog_green = 0x4C943D # Used for FROGTIPS
red = 0xe74c3c # Used for on_error
dark_red = 0x992d22 # Used for on_command_error



# REMEMBER TO UNCOMMENT THE GSS LINE, ROXIE # REMEMBER TO UNCOMMENT THE GSS LINE, ROXIE



+ 4
- 4
Roxbot/logging.py View File

import discord import discord
from Roxbot import guild_settings, embedcolour
from Roxbot import guild_settings, EmbedColours




async def log(guild, channel, command_name, **kwargs): async def log(guild, channel, command_name, **kwargs):
logging = guild_settings.get(guild).logging logging = guild_settings.get(guild).logging
if logging["enabled"]: if logging["enabled"]:
embed = discord.Embed(title="{} command logging".format(command_name), colour=embedcolour)
embed = discord.Embed(title="{} command logging".format(command_name), colour=EmbedColours.pink)
for key, value in kwargs.items(): for key, value in kwargs.items():
embed.add_field(name=key, value=value) embed.add_field(name=key, value=value)
return await channel.send(embed=embed) return await channel.send(embed=embed)
logging = guild_settings.get(member.guild).logging logging = guild_settings.get(member.guild).logging
if logging["enabled"]: if logging["enabled"]:
channel = self.bot.get_channel(logging["channel"]) channel = self.bot.get_channel(logging["channel"])
embed = discord.Embed(title="{} joined the server".format(member), colour=embedcolour)
embed = discord.Embed(title="{} joined the server".format(member), colour=EmbedColours.pink)
embed.add_field(name="ID", value=member.id) embed.add_field(name="ID", value=member.id)
embed.add_field(name="Mention", value=member.mention) embed.add_field(name="Mention", value=member.mention)
embed.add_field(name="Date Account Created", value="{:%a %Y/%m/%d %H:%M:%S} UTC".format(member.created_at)) embed.add_field(name="Date Account Created", value="{:%a %Y/%m/%d %H:%M:%S} UTC".format(member.created_at))
logging = guild_settings.get(member.guild).logging logging = guild_settings.get(member.guild).logging
if logging["enabled"]: if logging["enabled"]:
channel = self.bot.get_channel(logging["channel"]) channel = self.bot.get_channel(logging["channel"])
embed = discord.Embed(description="{} left the server".format(member), colour=embedcolour)
embed = discord.Embed(description="{} left the server".format(member), colour=EmbedColours.pink)
return await channel.send(embed=embed) return await channel.send(embed=embed)





+ 2
- 2
Roxbot/settings/settings.py View File

import asyncio import asyncio
import datetime import datetime


from Roxbot import checks, load_config, guild_settings
from Roxbot import checks, load_config, guild_settings, EmbedColours


import discord import discord
from discord.ext.commands import bot, group, is_owner, bot_has_permissions from discord.ext.commands import bot, group, is_owner, bot_has_permissions
async def printsettings(self, ctx, option=None): async def printsettings(self, ctx, option=None):
"OWNER OR ADMIN ONLY: Prints the servers settings file." "OWNER OR ADMIN ONLY: Prints the servers settings file."
config = guild_settings.get(ctx.guild) config = guild_settings.get(ctx.guild)
em = discord.Embed(colour=0xDEADBF)
em = discord.Embed(colour=EmbedColours.pink)
em.set_author(name="{} settings for {}.".format(self.bot.user.name, ctx.message.guild.name), icon_url=self.bot.user.avatar_url) em.set_author(name="{} settings for {}.".format(self.bot.user.name, ctx.message.guild.name), icon_url=self.bot.user.avatar_url)
if option in config.settings: if option in config.settings:
settingcontent = "" settingcontent = ""

+ 1
- 1
main.py View File

Outputs info about RoxBot, showing uptime, how to report issues, what settings where set in prefs.ini and credits. Outputs info about RoxBot, showing uptime, how to report issues, what settings where set in prefs.ini and credits.
""" """
owner = bot.get_user(Roxbot.owner) owner = bot.get_user(Roxbot.owner)
em = discord.Embed(title="About Roxbot", colour=Roxbot.embedcolour, description=Roxbot.__description__)
em = discord.Embed(title="About Roxbot", colour=Roxbot.EmbedColours.pink, description=Roxbot.__description__)
em.set_thumbnail(url=bot.user.avatar_url) em.set_thumbnail(url=bot.user.avatar_url)
em.add_field(name="Command Prefix", value=Roxbot.command_prefix) em.add_field(name="Command Prefix", value=Roxbot.command_prefix)
em.add_field(name="Owner", value=str(owner)) em.add_field(name="Owner", value=str(owner))

Loading…
Cancel
Save