1
0
Fork 0
mirror of synced 2024-06-21 12:00:16 +12:00

Mass update: removed all cases LikeThis and replaced them like_this (This for you Fuyu)

This commit is contained in:
Phxntxm 2016-08-14 21:10:12 -05:00
parent 8ddf0c4588
commit 37dbacf3fe
18 changed files with 194 additions and 191 deletions

15
bot.py
View file

@ -22,7 +22,10 @@ extensions = ['cogs.interaction',
'cogs.links',
'cogs.tags',
'cogs.roles',
'cogs.statsupdate']
'cogs.statsupdate',
'cogs.strawpoll',
'cogs.tictactoe',
'cogs.hangman']
bot = commands.Bot(command_prefix=config.commandPrefix, description=config.botDescription, pm_help=None)
discord_logger = logging.getLogger('discord')
@ -40,22 +43,22 @@ log.addHandler(handler)
async def on_ready():
# Change the status upon connection to the default status
await bot.change_status(discord.Game(name=config.defaultStatus, type=0))
channel_id = config.getContent('restart_server')
channel_id = config.get_content('restart_server')
# Just in case the bot was restarted while someone was battling, clear it so they do not get stuck
config.saveContent('battling', {})
config.save_content('battling', {})
# Check if the bot was restarted, if so
if channel_id != 0:
destination = discord.utils.find(lambda m: m.id == channel_id, bot.get_all_channels())
await bot.send_message(destination, "I have just finished restarting!")
config.saveContent('restart_server', 0)
config.save_content('restart_server', 0)
if not hasattr(bot, 'uptime'):
bot.uptime = pendulum.utcnow()
@bot.event
async def on_member_join(member):
notifications = config.getContent('user_notifications') or {}
notifications = config.get_content('user_notifications') or {}
server_notifications = notifications.get(member.server.id)
if not server_notifications:
return
@ -66,7 +69,7 @@ async def on_member_join(member):
@bot.event
async def on_member_remove(member):
notifications = config.getContent('user_notifications') or {}
notifications = config.get_content('user_notifications') or {}
server_notifications = notifications.get(member.server.id)
if not server_notifications:
return

View file

@ -20,7 +20,7 @@ class Core:
self.bot = bot
@commands.command()
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def calendar(self, month: str=None, year: int=None):
"""Provides a printout of the current month's calendar
Provide month and year to print the calendar of that year and month"""
@ -51,7 +51,7 @@ class Core:
await self.bot.say("```\n{}```".format(cal))
@commands.command()
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def info(self):
"""This command can be used to print out some of my information"""
fmt = {}
@ -76,13 +76,13 @@ class Core:
await self.bot.say("```\n{}```".format(information))
@commands.command()
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def uptime(self):
"""Provides a printout of the current bot's uptime"""
await self.bot.say("Uptime: ```\n{}```".format((pendulum.utcnow() - self.bot.uptime).in_words()))
@commands.command(aliases=['invite'])
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def addbot(self):
"""Provides a link that you can use to add me to a server"""
perms = discord.Permissions.none()
@ -99,7 +99,7 @@ class Core:
.format(discord.utils.oauth_url('183748889814237186', perms)))
@commands.command(pass_context=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def doggo(self, ctx):
"""Use this to print a random doggo image.
Doggo is love, doggo is life."""
@ -108,7 +108,7 @@ class Core:
await self.bot.upload(f)
@commands.command(pass_context=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def snek(self, ctx):
"""Use this to print a random snek image.
Sneks are o3o"""
@ -117,15 +117,15 @@ class Core:
await self.bot.upload(f)
@commands.command()
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def joke(self):
"""Prints a random riddle"""
fortuneCommand = "/usr/bin/fortune riddles"
fortune = subprocess.check_output(fortuneCommand.split()).decode("utf-8")
fortune_command = "/usr/bin/fortune riddles"
fortune = subprocess.check_output(fortune_command.split()).decode("utf-8")
await self.bot.say(fortune)
@commands.command(pass_context=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def roll(self, ctx, notation: str="d6"):
"""Rolls a die based on the notation given
Format should be #d#"""
@ -146,13 +146,13 @@ class Core:
await self.bot.say("What die has more than 100 sides? Please, calm down")
return
valueStr = ", ".join(str(random.SystemRandom().randint(1, num)) for i in range(0, int(dice)))
value_str = ", ".join(str(random.SystemRandom().randint(1, num)) for i in range(0, int(dice)))
if dice == 1:
fmt = '{0.message.author.name} has rolled a {2} sided die and got the number {3}!'
else:
fmt = '{0.message.author.name} has rolled {1}, {2} sided dice and got the numbers {3}!'
await self.bot.say(fmt.format(ctx, dice, num, valueStr))
await self.bot.say(fmt.format(ctx, dice, num, value_str))
def setup(bot):

View file

@ -68,7 +68,7 @@ class Hangman:
@commands.group(aliases=['hm'], pass_context=True, no_pm=True, invoke_without_command=True)
@commands.cooldown(1, 30, BucketType.user)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def hangman(self, ctx, *, guess):
"""Makes a guess towards the server's currently running hangman game"""
game = self.games.get(ctx.message.server.id)
@ -105,7 +105,7 @@ class Hangman:
await self.bot.say(fmt)
@hangman.command(name='create', aliases=['start'], no_pm=True, pass_context=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def create_hangman(self, ctx):
"""This is used to create a new hangman game
Due to the fact that I might not be able to delete a message, I will PM you and ask for the phrase you want.

View file

@ -6,16 +6,16 @@ import discord
import random
def battlingOff(player_id):
battling = config.getContent('battling')
def battling_off(player_id):
battling = config.get_content('battling')
battling = {p1: p2 for p1, p2 in battling.items() if not p2 == player_id and not p1 == player_id}
config.saveContent('battling', battling)
config.save_content('battling', battling)
def userBattling(ctx):
battling = config.getContent('battling')
def user_battling(ctx):
battling = config.get_content('battling')
if battling is None:
return False
if ctx.message.author.id in battling.values() or ctx.message.author.id in battling.keys():
@ -26,8 +26,8 @@ def userBattling(ctx):
return False
def updateBattleRecords(winner, loser):
battles = config.getContent('battle_records')
def update_battle_records(winner, loser):
battles = config.get_content('battle_records')
if battles is None:
battles = {winner.id: "1-0", loser.id: "0-1"}
@ -65,7 +65,7 @@ def updateBattleRecords(winner, loser):
battles[winner.id] = winner_stats
battles[loser.id] = loser_stats
return config.saveContent('battle_records', battles)
return config.save_content('battle_records', battles)
class Interaction:
@ -76,7 +76,7 @@ class Interaction:
@commands.group(pass_context=True, no_pm=True, invoke_without_command=True)
@commands.cooldown(1, 180, BucketType.user)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def battle(self, ctx, player2: discord.Member):
"""Challenges the mentioned user to a battle"""
if len(ctx.message.mentions) == 0:
@ -91,28 +91,28 @@ class Interaction:
if self.bot.user.id == player2.id:
await self.bot.say("I always win, don't even try it.")
return
if userBattling(ctx):
if user_battling(ctx):
await self.bot.say("You or the person you are trying to battle is already in a battle!")
return
battling = config.getContent('battling') or {}
battling = config.get_content('battling') or {}
battling[ctx.message.author.id] = ctx.message.mentions[0].id
config.saveContent('battling', battling)
config.save_content('battling', battling)
fmt = "{0.mention} has challenged you to a battle {1.mention}\n!accept or !decline"
config.loop.call_later(180, battlingOff, ctx.message.author.id)
config.loop.call_later(180, battling_off, ctx.message.author.id)
await self.bot.say(fmt.format(ctx.message.author, player2))
await self.bot.delete_message(ctx.message)
@commands.command(pass_context=True, no_pm=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def accept(self, ctx):
"""Accepts the battle challenge"""
if not userBattling(ctx):
if not user_battling(ctx):
await self.bot.say("You are not currently in a battle!")
return
battling = config.getContent('battling') or {}
battling = config.get_content('battling') or {}
p1 = [p1_id for p1_id, p2_id in battling.items() if p2_id == ctx.message.author.id]
if len(p1) == 0:
await self.bot.say("You are not currently being challenged to a battle!")
@ -122,26 +122,26 @@ class Interaction:
battleP2 = ctx.message.author
fmt = config.battleWins[random.SystemRandom().randint(0, len(config.battleWins) - 1)]
battlingOff(ctx.message.author.id)
battling_off(ctx.message.author.id)
if random.SystemRandom().randint(0, 1):
await self.bot.say(fmt.format(battleP1.mention, battleP2.mention))
updateBattleRecords(battleP1, battleP2)
update_battle_records(battleP1, battleP2)
else:
await self.bot.say(fmt.format(battleP2.mention, battleP1.mention))
updateBattleRecords(battleP2, battleP1)
update_battle_records(battleP2, battleP1)
await self.bot.delete_message(ctx.message)
@commands.command(pass_context=True, no_pm=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def decline(self, ctx):
"""Declines the battle challenge"""
if not userBattling(ctx):
if not user_battling(ctx):
await self.bot.say("You are not currently in a battle!")
return
battling = config.getContent('battling') or {}
battling = config.get_content('battling') or {}
p1 = [p1_id for p1_id, p2_id in battling.items() if p2_id == ctx.message.author.id]
if len(p1) == 0:
await self.bot.say("You are not currently being challenged to a battle!")
@ -149,13 +149,13 @@ class Interaction:
battleP1 = discord.utils.find(lambda m: m.id == p1[0], ctx.message.server.members)
battleP2 = ctx.message.author
battlingOff(ctx.message.author.id)
battling_off(ctx.message.author.id)
await self.bot.say("{0} has chickened out! What a loser~".format(battleP2.mention, battleP1.mention))
await self.bot.delete_message(ctx.message)
@commands.command(pass_context=True, no_pm=True)
@commands.cooldown(1, 180, BucketType.user)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def boop(self, ctx, boopee: discord.Member):
"""Boops the mentioned person"""
booper = ctx.message.author
@ -172,7 +172,7 @@ class Interaction:
await self.bot.say("Why the heck are you booping me? Get away from me >:c")
return
boops = config.getContent('boops') or {}
boops = config.get_content('boops') or {}
amount = 1
booper_boops = boops.get(ctx.message.author.id)
@ -186,7 +186,7 @@ class Interaction:
booper_boops[boopee.id] = amount
boops[ctx.message.author.id] = booper_boops
config.saveContent('boops', boops)
config.save_content('boops', boops)
fmt = "{0.mention} has just booped you {1.mention}! That's {2} times now!"
await self.bot.say(fmt.format(booper, boopee, amount))
await self.bot.delete_message(ctx.message)

View file

@ -13,7 +13,7 @@ class Links:
self.bot = bot
@commands.command()
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def urban(self, *msg: str):
"""Pulls the top urbandictionary.com definition for a term"""
url = "http://api.urbandictionary.com/v0/define?term={}".format('+'.join(msg))
@ -31,13 +31,13 @@ class Links:
await self.bot.say('```Error: Definition is too long for me to send```')
@commands.command(pass_context=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def derpi(self, ctx, *search: str):
"""Provides a random image from the first page of derpibooru.org for the following term"""
if len(search) > 0:
# This sets the url as url?q=search+terms
url = 'https://derpibooru.org/search.json?q={}'.format('+'.join(search))
nsfw_channels = config.getContent("nsfw_channels") or {}
nsfw_channels = config.get_content("nsfw_channels") or {}
if ctx.message.channel.id in nsfw_channels:
url += ",+explicit&filter_id=95938"
@ -69,7 +69,7 @@ class Links:
@commands.command(pass_context=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def e621(self, ctx, *, tags: str):
"""Searches for a random image from e621.net
Format for the search terms need to be 'search term 1, search term 2, etc.'
@ -79,7 +79,7 @@ class Links:
url = 'https://e621.net/post/index.json?limit=320&tags={}'.format(tags)
await self.bot.say("Looking up an image with those tags....")
nsfw_channels = config.getContent("nsfw_channels") or {}
nsfw_channels = config.get_content("nsfw_channels") or {}
if ctx.message.channel.id in nsfw_channels:
url += "%20rating:explicit"
else:

View file

@ -14,25 +14,25 @@ class Mod:
self.bot = bot
@commands.command(pass_context=True, no_pm=True)
@checks.customPermsOrRole(kick_members=True)
@checks.custom_perms(kick_members=True)
async def alerts(self, ctx, channel: discord.Channel):
"""This command is used to set a channel as the server's 'notifications' channel
Any notifications (like someone going live on Twitch, or Picarto) will go to that channel"""
server_alerts = config.getContent('server_alerts') or {}
server_alerts = config.get_content('server_alerts') or {}
server_alerts[ctx.message.server.id] = channel.id
await self.bot.say("I have just changed this server's 'notifications' channel"
"\nAll notifications will now go to `{}`".format(channel))
@commands.command(pass_context=True, no_pm=True)
@checks.customPermsOrRole(kick_members=True)
@checks.custom_perms(kick_members=True)
async def usernotify(self, ctx, on_off: str):
"""This command can be used to set whether or not you want user notificaitons to show
This will save what channel you run this command in, that will be the channel used to send the notification to
Provide on, yes, or true to set it on; otherwise it will be turned off"""
on_off = ctx.message.channel.id if re.search("(on|yes|true)", on_off.lower()) else None
notifications = config.getContent('user_notifications') or {}
notifications = config.get_content('user_notifications') or {}
notifications[ctx.message.server.id] = on_off
config.saveContent('user_notifications', notifications)
config.save_content('user_notifications', notifications)
fmt = "notify" if on_off else "not notify"
await self.bot.say("This server will now {} if someone has joined or left".format(fmt))
@ -43,38 +43,38 @@ class Mod:
await self.bot.say('Invalid subcommand passed: {0.subcommand_passed}'.format(ctx))
@nsfw.command(name="add", pass_context=True, no_pm=True)
@checks.customPermsOrRole(kick_members=True)
@checks.custom_perms(kick_members=True)
async def nsfw_add(self, ctx):
"""Registers this channel as a 'nsfw' channel"""
nsfw_channels = config.getContent('nsfw_channels') or {}
nsfw_channels = config.get_content('nsfw_channels') or {}
if ctx.message.channel.id in nsfw_channels:
await self.bot.say("This channel is already registered as 'nsfw'!")
else:
nsfw_channels.append(ctx.message.channel.id)
config.saveContent('nsfw_channels', nsfw_channels)
config.save_content('nsfw_channels', nsfw_channels)
await self.bot.say("This channel has just been registered as 'nsfw'! Have fun you naughties ;)")
@nsfw.command(name="remove", aliases=["delete"], pass_context=True, no_pm=True)
@checks.customPermsOrRole(kick_members=True)
@checks.custom_perms(kick_members=True)
async def nsfw_remove(self, ctx):
"""Removes this channel as a 'nsfw' channel"""
nsfw_channels = config.getContent('nsfw_channels') or {}
nsfw_channels = config.get_content('nsfw_channels') or {}
if ctx.message.channel.id not in nsfw_channels:
await self.bot.say("This channel is not registered as a ''nsfw' channel!")
else:
nsfw_channels.remove(ctx.message.channel.id)
config.saveContent('nsfw_channels', nsfw_channels)
config.save_content('nsfw_channels', nsfw_channels)
await self.bot.say("This channel has just been unregistered as a nsfw channel")
@commands.command(pass_context=True, no_pm=True)
@checks.customPermsOrRole(kick_members=True)
@checks.custom_perms(kick_members=True)
async def say(self, ctx, *, msg: str):
"""Tells the bot to repeat what you say"""
await self.bot.say(msg)
await self.bot.delete_message(ctx.message)
@commands.group(pass_context=True, invoke_without_command=True, no_pm=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def perms(self, ctx, *, command: str = None):
"""This command can be used to print the current allowed permissions on a specific command
This supports groups as well as subcommands; pass no argument to print a list of available permissions"""
@ -83,7 +83,7 @@ class Mod:
"Valid permissions are: ```\n{}```".format("\n".join("{}".format(i) for i in valid_perms)))
return
custom_perms = config.getContent('custom_permissions') or {}
custom_perms = config.get_content('custom_permissions') or {}
server_perms = custom_perms.get(ctx.message.server.id)
if server_perms is None:
await self.bot.say("There are no custom permissions setup on this server yet!")
@ -132,7 +132,7 @@ class Mod:
return
for check in cmd.checks:
if "isOwner" == check.__name__ or re.search("has_permissions", str(check)) is not None:
if "is_owner" == check.__name__ or re.search("has_permissions", str(check)) is not None:
await self.bot.say("This command cannot have custom permissions setup!")
return
@ -142,12 +142,12 @@ class Mod:
return
custom_perms = config.getContent('custom_permissions') or {}
custom_perms = config.get_content('custom_permissions') or {}
server_perms = custom_perms.get(ctx.message.server.id) or {}
server_perms[cmd.qualified_name] = perm_value
custom_perms[ctx.message.server.id] = server_perms
config.saveContent('custom_permissions', custom_perms)
config.save_content('custom_permissions', custom_perms)
await self.bot.say("I have just added your custom permissions; "
"you now need to have `{}` permissions to use the command `{}`".format(permissions, command))
@ -156,7 +156,7 @@ class Mod:
async def remove_perms(self, ctx, *command: str):
"""Removes the custom permissions setup on the command specified"""
cmd = " ".join(command)
custom_perms = config.getContent('custom_permissions') or {}
custom_perms = config.get_content('custom_permissions') or {}
server_perms = custom_perms.get(ctx.message.server.id) or {}
if server_perms is None:
await self.bot.say("There are no custom permissions setup on this server yet!")
@ -166,20 +166,20 @@ class Mod:
await self.bot.say("You do not have custom permissions setup on this command yet!")
return
del custom_perms[ctx.message.server.id][cmd]
config.saveContent('custom_permissions', custom_perms)
config.save_content('custom_permissions', custom_perms)
await self.bot.say("I have just removed the custom permissions for {}!".format(cmd))
@commands.command(pass_context=True, no_pm=True)
@checks.customPermsOrRole(manage_messages=True)
@checks.custom_perms(manage_messages=True)
async def purge(self, ctx, limit: int = 100):
"""This command is used to a purge a number of messages from the channel"""
await self.bot.purge_from(ctx.message.channel, limit=limit)
@commands.group(aliases=['rule'], pass_context=True, no_pm=True, invoke_without_command=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def rules(self, ctx):
"""This command can be used to view the current rules on the server"""
rules = config.getContent('rules') or {}
rules = config.get_content('rules') or {}
server_rules = rules.get(ctx.message.server.id)
if server_rules is None or len(server_rules) == 0:
await self.bot.say("This server currently has no rules on it! I see you like to live dangerously...")
@ -188,23 +188,23 @@ class Mod:
await self.bot.say('```\n{}```'.format(fmt))
@rules.command(name='add', aliases=['create'], pass_context=True, no_pm=True)
@checks.customPermsOrRole(manage_server=True)
@checks.custom_perms(manage_server=True)
async def rules_add(self, ctx, *, rule: str):
"""Adds a rule to this server's rules"""
rules = config.getContent('rules') or {}
rules = config.get_content('rules') or {}
server_rules = rules.get(ctx.message.server.id) or []
server_rules.append(rule)
rules[ctx.message.server.id] = server_rules
config.saveContent('rules', rules)
config.save_content('rules', rules)
await self.bot.say("I have just saved your new rule, use the rules command to view this server's current rules")
@rules.command(name='remove', aliases=['delete'], pass_context=True, no_pm=True)
@checks.customPermsOrRole(manage_server=True)
@checks.custom_perms(manage_server=True)
async def rules_delete(self, ctx, rule: int = None):
"""Removes one of the rules from the list of this server's rules
Provide a number to delete that rule; if no number is provided
I'll print your current rules and ask for a number"""
rules = config.getContent('rules') or {}
rules = config.get_content('rules') or {}
server_rules = rules.get(ctx.message.server.id)
if server_rules is None or len(server_rules) == 0:
await self.bot.say(
@ -223,12 +223,12 @@ class Mod:
return
del server_rules[int(msg.content) - 1]
rules[ctx.message.server.id] = server_rules
config.saveContent('rules', rules)
config.save_content('rules', rules)
try:
del server_rules[rule - 1]
rules[ctx.message.server.id] = server_rules
config.saveContent('rules', rules)
config.save_content('rules', rules)
await self.bot.say("I have just removed that rule from your list of rules!")
except IndexError:
await self.bot.say("That is not a valid rule number, try running the command again. "

View file

@ -27,14 +27,14 @@ class Overwatch:
pass
@ow.command(name="stats", pass_context=True, no_pm=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def ow_stats(self, ctx, user: discord.Member=None, hero: str=""):
"""Prints out a basic overview of a member's stats
Provide a hero after the member to get stats for that specific hero"""
if user is None:
user = ctx.message.author
ow_stats = config.getContent('overwatch') or {}
ow_stats = config.get_content('overwatch') or {}
bt = ow_stats.get(user.id)
if bt is None:
@ -79,7 +79,7 @@ class Overwatch:
.format(user.name, hero.title(), fmt.title().replace("_", " ")))
@ow.command(pass_context=True, name="add", no_pm=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def add(self, ctx, bt: str):
"""Saves your battletag for looking up information"""
bt = bt.replace("#", "-")
@ -93,15 +93,15 @@ class Overwatch:
"format needs to be `user#xxxx`. Capitalization matters")
return
ow = config.getContent('overwatch') or {}
ow = config.get_content('overwatch') or {}
ow[ctx.message.author.id] = bt
await self.bot.say("I have just saved your battletag {}".format(ctx.message.author.mention))
@ow.command(pass_context=True, name="delete", aliases=['remove'], no_pm=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def delete(self, ctx):
"""Removes your battletag from the records"""
result = config.getContent('overwatch') or {}
result = config.get_content('overwatch') or {}
if result.get(ctx.message.author.id):
del result[ctx.message.author.id]
await self.bot.say("I no longer have your battletag saved {}".format(ctx.message.author.mention))

View file

@ -20,16 +20,16 @@ class Owner:
self.bot = bot
@commands.command(pass_context=True)
@commands.check(checks.isOwner)
@commands.check(checks.is_owner)
async def restart(self, ctx):
"""Forces the bot to restart"""
config.saveContent('restart_server', ctx.message.channel.id)
config.save_content('restart_server', ctx.message.channel.id)
await self.bot.say("Restarting; see you in the next life {0}!".format(ctx.message.author.mention))
python = sys.executable
os.execl(python, python, *sys.argv)
@commands.command()
@commands.check(checks.isOwner)
@commands.check(checks.is_owner)
async def adddoggo(self, url: str):
"""Saves a URL as an image to add for the doggo command"""
local_path = 'images/doggo{}.jpg'.format(len(glob.glob('doggo*')))
@ -42,7 +42,7 @@ class Owner:
"Just saved a new doggo image! I now have {} doggo images!".format(len(glob.glob('doggo*'))))
@commands.command()
@commands.check(checks.isOwner)
@commands.check(checks.is_owner)
async def addsnek(self, url: str):
"""Saves a URL as an image to add for the snek command"""
local_path = 'images/snek{}.jpg'.format(len(glob.glob('snek*')))
@ -55,7 +55,7 @@ class Owner:
"Just saved a new snek image! I now have {} snek images!".format(len(glob.glob('snek*'))))
@commands.command(pass_context=True)
@commands.check(checks.isOwner)
@commands.check(checks.is_owner)
async def debug(self, ctx):
"""Executes code"""
try:
@ -76,7 +76,7 @@ class Owner:
await self.bot.say(fmt.format(type(error).__name__, error))
@commands.command(pass_context=True)
@commands.check(checks.isOwner)
@commands.check(checks.is_owner)
async def shutdown(self, ctx):
"""Shuts the bot down"""
fmt = 'Shutting down, I will miss you {0.author.name}'
@ -85,7 +85,7 @@ class Owner:
await self.bot.close()
@commands.command()
@commands.check(checks.isOwner)
@commands.check(checks.is_owner)
async def avatar(self, content: str):
"""Changes the avatar for the bot to the filename following the command"""
file = 'images/' + content
@ -93,14 +93,14 @@ class Owner:
await self.bot.edit_profile(avatar=fp.read())
@commands.command()
@commands.check(checks.isOwner)
@commands.check(checks.is_owner)
async def name(self, newNick: str):
"""Changes the bot's name"""
await self.bot.edit_profile(username=newNick)
await self.bot.say('Changed username to ' + newNick)
@commands.command()
@commands.check(checks.isOwner)
@commands.check(checks.is_owner)
async def status(self, *stat: str):
"""Changes the bot's 'playing' status"""
newStatus = ' '.join(stat)
@ -109,7 +109,7 @@ class Owner:
await self.bot.say("Just changed my status to '{0}'!".format(newStatus))
@commands.command()
@commands.check(checks.isOwner)
@commands.check(checks.is_owner)
async def load(self, *, module: str):
"""Loads a module"""
module = module.lower()
@ -123,7 +123,7 @@ class Owner:
await self.bot.say(fmt.format(type(error).__name__, error))
@commands.command()
@commands.check(checks.isOwner)
@commands.check(checks.is_owner)
async def unload(self, *, module: str):
"""Unloads a module"""
module = module.lower()
@ -137,7 +137,7 @@ class Owner:
await self.bot.say(fmt.format(type(error).__name__, error))
@commands.command()
@commands.check(checks.isOwner)
@commands.check(checks.is_owner)
async def reload(self, *, module: str):
"""Reloads a module"""
module = module.lower()

View file

@ -35,7 +35,7 @@ class Picarto:
async def check_channels(self):
await self.bot.wait_until_ready()
while not self.bot.is_closed:
picarto = config.getContent('picarto') or {}
picarto = config.get_content('picarto') or {}
online_users_list = await online_users()
for m_id, r in picarto.items():
url = r['picarto_url']
@ -47,19 +47,19 @@ class Picarto:
if not live and notify and online:
for server_id in r['servers'].items():
server = self.bot.get_server(server_id)
server_alerts = config.getContent('server_alerts') or {}
server_alerts = config.get_content('server_alerts') or {}
channel_id = server_alerts.get(server_id) or server_id
channel = self.bot.get_channel(channel_id)
member = discord.utils.find(lambda m: m.id == m_id, server.members)
picarto[m_id]['live'] = 1
fmt = "{} has just gone live! View their stream at {}".format(member.display_name, url)
config.saveContent('picarto', picarto)
config.save_content('picarto', picarto)
await self.bot.send_message(channel, fmt)
elif live and not online:
for server_id, channel_id in r['servers'].items():
server = self.bot.get_server(server_id)
server_alerts = config.getContent('server_alerts') or {}
server_alerts = config.get_content('server_alerts') or {}
channel_id = server_alerts.get(server_id) or server_id
channel = self.bot.get_channel(channel_id)
member = discord.utils.find(lambda m: m.id == m_id, server.members)
@ -68,16 +68,16 @@ class Picarto:
fmt = "{} has just gone offline! Catch them next time they stream at {}".format(
member.display_name,
url)
config.saveContent('picarto', picarto)
config.save_content('picarto', picarto)
await self.bot.send_message(channel, fmt)
await asyncio.sleep(30)
@commands.group(pass_context=True, invoke_without_command=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def picarto(self, ctx, member: discord.Member = None):
"""This command can be used to view Picarto stats about a certain member"""
member = member or ctx.message.author
picarto_urls = config.getContent('picarto') or {}
picarto_urls = config.get_content('picarto') or {}
member_url = picarto_urls.get(member.id)
if not member_url:
await self.bot.say("That user does not have a picarto url setup!")
@ -102,7 +102,7 @@ class Picarto:
await self.bot.say("Picarto stats for {}: ```\n{}```".format(member.display_name, fmt))
@picarto.command(name='add', pass_context=True, no_pm=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def add_picarto_url(self, ctx, url: str):
"""Saves your user's picarto URL"""
try:
@ -121,7 +121,7 @@ class Picarto:
"What would be the point of adding a nonexistant Picarto user? Silly")
return
picarto_urls = config.getContent('picarto') or {}
picarto_urls = config.get_content('picarto') or {}
result = picarto_urls.get(ctx.message.author.id)
if result is not None:
@ -130,19 +130,19 @@ class Picarto:
picarto_urls[ctx.message.author.id] = {'picarto_url': url,
'servers': {ctx.message.server.id: ctx.message.channel.id},
'notifications_on': 1, 'live': 0}
config.saveContent('picarto', picarto_urls)
config.save_content('picarto', picarto_urls)
await self.bot.say(
"I have just saved your Picarto url {}, this channel will now send a notification when you go live".format(
ctx.message.author.mention))
@picarto.command(name='remove', aliases=['delete'], pass_context=True, no_pm=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def remove_picarto_url(self, ctx):
"""Removes your picarto URL"""
picarto = config.getContent('picarto') or {}
picarto = config.get_content('picarto') or {}
if picarto.get(ctx.message.author.id) is not None:
del picarto[ctx.message.author.id]
config.saveContent('picarto', picarto)
config.save_content('picarto', picarto)
await self.bot.say("I am no longer saving your picarto URL {}".format(ctx.message.author.mention))
else:
await self.bot.say(
@ -150,14 +150,14 @@ class Picarto:
ctx.message.author.mention))
@picarto.group(pass_context=True, no_pm=True, invoke_without_command=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def notify(self, ctx, channel: discord.Channel = None):
"""This can be used to turn picarto notifications on or off
Call this command by itself, with a channel name, to change which one has the notification sent to it"""
channel = channel or ctx.message.channel
member = ctx.message.author
picarto = config.getContent('picarto') or {}
picarto = config.get_content('picarto') or {}
result = picarto.get(member.id)
if result is None:
await self.bot.say(
@ -165,15 +165,15 @@ class Picarto:
member.mention))
picarto[member.id]['servers'][ctx.message.server.id] = channel.id
config.saveContent('picarto', picarto)
config.save_content('picarto', picarto)
await self.bot.say(
"I have just changed which channel will be notified when you go live, to `{}`".format(channel.name))
@notify.command(name='on', aliases=['start,yes'], pass_context=True, no_pm=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def notify_on(self, ctx):
"""Turns picarto notifications on"""
picarto = config.getContent('picarto') or {}
picarto = config.get_content('picarto') or {}
result = picarto.get(ctx.message.author.id)
if result is None:
await self.bot.say(
@ -184,15 +184,15 @@ class Picarto:
ctx.message.author.mention))
else:
picarto[ctx.message.author.id]['notifications_on'] = 1
config.saveContent('picarto', picarto)
config.save_content('picarto', picarto)
await self.bot.say("I will notify if you go live {}, you'll get a bajillion followers I promise c:".format(
ctx.message.author.mention))
@notify.command(name='off', aliases=['stop,no'], pass_context=True, no_pm=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def notify_off(self, ctx):
"""Turns picarto notifications off"""
picarto = config.getContent('picarto') or {}
picarto = config.get_content('picarto') or {}
if picarto.get(ctx.message.author.id) is None:
await self.bot.say(
"I do not have your picarto URL added {}. You can save your picarto url with !picarto add".format(
@ -202,7 +202,7 @@ class Picarto:
ctx.message.author.mention))
else:
picarto[ctx.message.author.id]['notifications_on'] = 0
config.saveContent('picarto', picarto)
config.save_content('picarto', picarto)
await self.bot.say(
"I will not notify if you go live anymore {}, "
"are you going to stream some lewd stuff you don't want people to see?~".format(

View file

@ -101,7 +101,7 @@ class Music:
pass
@commands.command(no_pm=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def join(self, *, channel: discord.Channel):
"""Joins a voice channel."""
try:
@ -117,7 +117,7 @@ class Music:
await self.bot.say('Ready to play audio in ' + channel.name)
@commands.command(pass_context=True, no_pm=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def summon(self, ctx):
"""Summons the bot to join your voice channel."""
summoned_channel = ctx.message.author.voice_channel
@ -133,7 +133,7 @@ class Music:
return True
@commands.command(pass_context=True, no_pm=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def play(self, ctx, *, song: str):
"""Plays a song.
If there is a song currently in the queue, then it is
@ -170,7 +170,7 @@ class Music:
await state.songs.put(entry)
@commands.command(pass_context=True, no_pm=True)
@checks.customPermsOrRole(kick_members=True)
@checks.custom_perms(kick_members=True)
async def volume(self, ctx, value: int):
"""Sets the volume of the currently playing song."""
@ -181,7 +181,7 @@ class Music:
await self.bot.say('Set the volume to {:.0%}'.format(player.volume))
@commands.command(pass_context=True, no_pm=True)
@checks.customPermsOrRole(kick_members=True)
@checks.custom_perms(kick_members=True)
async def pause(self, ctx):
"""Pauses the currently played song."""
state = self.get_voice_state(ctx.message.server)
@ -190,7 +190,7 @@ class Music:
player.pause()
@commands.command(pass_context=True, no_pm=True)
@checks.customPermsOrRole(kick_members=True)
@checks.custom_perms(kick_members=True)
async def resume(self, ctx):
"""Resumes the currently played song."""
state = self.get_voice_state(ctx.message.server)
@ -199,7 +199,7 @@ class Music:
player.resume()
@commands.command(pass_context=True, no_pm=True)
@checks.customPermsOrRole(kick_members=True)
@checks.custom_perms(kick_members=True)
async def stop(self, ctx):
"""Stops playing audio and leaves the voice channel.
This also clears the queue.
@ -219,7 +219,7 @@ class Music:
pass
@commands.command(pass_context=True, no_pm=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def eta(self, ctx):
"""Provides an ETA on when your next song will play"""
state = self.get_voice_state(ctx.message.server)
@ -248,7 +248,7 @@ class Music:
await self.bot.say("ETA till your next play is: {0[0]}m {0[1]}s".format(divmod(round(count, 0), 60)))
@commands.command(pass_context=True, no_pm=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def queue(self, ctx):
"""Provides a printout of the songs that are in the queue"""
state = self.get_voice_state(ctx.message.server)
@ -262,14 +262,14 @@ class Music:
await self.bot.say("Current songs in the queue:```\n{}```".format(fmt))
@commands.command(pass_context=True, no_pm=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def queuelength(self, ctx):
"""Prints the length of the queue"""
await self.bot.say("There are a total of {} songs in the queue"
.format(str(self.get_voice_state(ctx.message.server).songs.qsize())))
@commands.command(pass_context=True, no_pm=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def skip(self, ctx):
"""Vote to skip a song. The song requester can automatically skip.
3 skip votes are needed for the song to be skipped.
@ -296,7 +296,7 @@ class Music:
await self.bot.say('You have already voted to skip this song.')
@commands.command(pass_context=True, no_pm=True)
@checks.customPermsOrRole(kick_members=True)
@checks.custom_perms(kick_members=True)
async def modskip(self, ctx):
"""Forces a song skip, can only be used by a moderator"""
state = self.get_voice_state(ctx.message.server)
@ -308,7 +308,7 @@ class Music:
await self.bot.say('Song has just been skipped.')
@commands.command(pass_context=True, no_pm=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def playing(self, ctx):
"""Shows info about the currently played song."""

View file

@ -11,7 +11,7 @@ class Roles:
self.bot = bot
@commands.group(aliases=['roles'], invoke_without_command=True, no_pm=True, pass_context=True)
@checks.customPermsOrRole(manage_server=True)
@checks.custom_perms(manage_server=True)
async def role(self, ctx):
"""This command can be used to modify the roles on the server.
Pass no subcommands and this will print the roles currently available on this server"""
@ -19,7 +19,7 @@ class Roles:
await self.bot.say("Your server's roles are: ```\n{}```".format("\n".join(server_roles)))
@role.command(name='remove', pass_context=True, no_pm=True)
@checks.customPermsOrRole(manage_server=True)
@checks.custom_perms(manage_server=True)
async def remove_role(self, ctx):
"""Use this to remove roles from a number of members"""
server_roles = [role for role in ctx.message.server.roles if not role.is_everyone]
@ -60,7 +60,7 @@ class Roles:
"```\n{}```".format("\n".join(role_names), "\n".join([m.display_name for m in members])))
@role.command(name='add', pass_context=True, no_pm=True)
@checks.customPermsOrRole(manage_server=True)
@checks.custom_perms(manage_server=True)
async def add_role(self, ctx):
"""Use this to add a role to multiple members.
Provide the list of members, and I'll ask for the role
@ -104,7 +104,7 @@ class Roles:
"```\n{}```".format("\n".join(role_names), "\n".join([m.display_name for m in members])))
@role.command(name='delete', pass_context=True, no_pm=True)
@checks.customPermsOrRole(manage_server=True)
@checks.custom_perms(manage_server=True)
async def delete_role(self, ctx, *, role: discord.Role = None):
"""This command can be used to delete one of the roles from the server"""
if role is None:
@ -124,7 +124,7 @@ class Roles:
await self.bot.say("I have just removed the role {} from this server".format(role.name))
@role.command(name='create', pass_context=True, no_pm=True)
@checks.customPermsOrRole(manage_server=True)
@checks.custom_perms(manage_server=True)
async def create_role(self, ctx):
"""This command can be used to create a new role for this server
A prompt will follow asking what settings you would like for this new role

View file

@ -11,10 +11,10 @@ class Stats:
self.bot = bot
@commands.command(pass_context=True, no_pm=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def mostboops(self, ctx):
"""Shows the person you have 'booped' the most, as well as how many times"""
boops = config.getContent('boops') or {}
boops = config.get_content('boops') or {}
if not boops.get(ctx.message.author.id):
await self.bot.say("You have not booped anyone {} Why the heck not...?".format(ctx.message.author.mention))
return
@ -30,10 +30,10 @@ class Stats:
ctx.message.author.mention, member.mention, most_boops))
@commands.command(pass_context=True, no_pm=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def listboops(self, ctx):
"""Lists all the users you have booped and the amount of times"""
boops = config.getContent('boops') or {}
boops = config.get_content('boops') or {}
booped_members = boops.get(ctx.message.author.id)
if booped_members is None:
await self.bot.say("You have not booped anyone {} Why the heck not...?".format(ctx.message.author.mention))
@ -48,10 +48,10 @@ class Stats:
await self.bot.say("You have booped:```\n{}```".format(output))
@commands.command(pass_context=True, no_pm=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def leaderboard(self, ctx):
"""Prints a leaderboard of everyone in the server's battling record"""
battles = config.getContent('battle_records') or {}
battles = config.get_content('battle_records') or {}
server_member_ids = [member.id for member in ctx.message.server.members]
server_members = {member_id: stats for member_id, stats in battles.items() if member_id in server_member_ids}
@ -68,12 +68,12 @@ class Stats:
await self.bot.say("Battling leaderboard for this server:```\n{}```".format(fmt))
@commands.command(pass_context=True, no_pm=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def stats(self, ctx, member: discord.Member=None):
"""Prints the battling stats for you, or the user provided"""
member = member or ctx.message.author
all_members = config.getContent('battle_records') or {}
all_members = config.get_content('battle_records') or {}
if member.id not in all_members:
await self.bot.say("That user has not battled yet!")
return

View file

@ -29,10 +29,10 @@ class Strawpoll:
self.session = aiohttp.ClientSession()
@commands.group(aliases=['strawpoll', 'poll', 'polls'], pass_context=True, invoke_without_command=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def strawpolls(self, ctx, poll_id: str = None):
"""This command can be used to show a strawpoll setup on this server"""
all_polls = config.getContent('strawpolls') or {}
all_polls = config.get_content('strawpolls') or {}
server_polls = all_polls.get(ctx.message.server.id) or {}
if not server_polls:
await self.bot.say("There are currently no strawpolls running on this server!")
@ -58,7 +58,7 @@ class Strawpoll:
await self.bot.say("```\n{}```".format(fmt))
@strawpolls.command(name='create', aliases=['setup', 'add'], pass_context=True)
@checks.customPermsOrRole(kick_members=True)
@checks.custom_perms(kick_members=True)
async def create_strawpoll(self, ctx, title, *, options):
"""This command is used to setup a new strawpoll
The format needs to be: poll create "title here" all options here
@ -82,21 +82,21 @@ class Strawpoll:
async with self.session.post(self.url, data=json.dumps(payload), headers=self.headers) as response:
data = await response.json()
all_polls = config.getContent('strawpolls') or {}
all_polls = config.get_content('strawpolls') or {}
server_polls = all_polls.get(ctx.message.server.id) or {}
server_polls[data['id']] = {'author': ctx.message.author.id, 'date': str(pendulum.utcnow()), 'title': title}
all_polls[ctx.message.server.id] = server_polls
config.saveContent('strawpolls', all_polls)
config.save_content('strawpolls', all_polls)
await self.bot.say("Link for your new strawpoll: https://strawpoll.me/{}".format(data['id']))
@strawpolls.command(name='delete', aliases=['remove', 'stop'], pass_context=True)
@checks.customPermsOrRole(kick_members=True)
@checks.custom_perms(kick_members=True)
async def remove_strawpoll(self, ctx, poll_id: str = None):
"""This command can be used to delete one of the existing strawpolls
If you don't provide an ID it will print the list of polls available"""
all_polls = config.getContent('strawpolls') or {}
all_polls = config.get_content('strawpolls') or {}
server_polls = all_polls.get(ctx.message.server.id) or {}
if poll_id:
@ -108,7 +108,7 @@ class Strawpoll:
else:
del server_polls[poll_id]
all_polls[ctx.message.server.id] = server_polls
config.saveContent('strawpolls', all_polls)
config.save_content('strawpolls', all_polls)
await self.bot.say("I have just removed the poll with the ID {}".format(poll_id))
else:
fmt = "\n".join("{}: {}".format(data['title'], _poll_id) for _poll_id, data in server_polls.items())

View file

@ -11,19 +11,19 @@ class Tags:
self.bot = bot
@commands.command(pass_context=True, no_pm=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def tags(self, ctx):
"""Prints all the custom tags that this server currently has"""
tags = config.getContent('tags') or {}
tags = config.get_content('tags') or {}
fmt = "\n".join("{}".format(tag['tag']) for tag in tags if tag['server_id'] == ctx.message.server.id)
await self.bot.say('```\n{}```'.format(fmt))
@commands.group(pass_context=True, invoke_without_command=True, no_pm=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def tag(self, ctx, *, tag: str):
"""This can be used to call custom tags
The format to call a custom tag is !tag <tag>"""
tags = config.getContent('tags') or {}
tags = config.get_content('tags') or {}
result = [t for t in tags if t['tag'] == tag and t['server_id'] == ctx.message.server.id]
if len(result) == 0:
await self.bot.say('That tag does not exist!')
@ -31,7 +31,7 @@ class Tags:
await self.bot.say("{}".format(result[0]['result']))
@tag.command(name='add', aliases=['create', 'start'], pass_context=True, no_pm=True)
@checks.customPermsOrRole(kick_members=True)
@checks.custom_perms(kick_members=True)
async def add_tag(self, ctx, *, result: str):
"""Use this to add a new tag that can be used in this server
Format to add a tag is !tag add <tag> - <result>"""
@ -45,7 +45,7 @@ class Tags:
await self.bot.say("Please provide the format for the tag in: !tag add <tag> - <result>")
return
tags = config.getContent('tags') or {}
tags = config.get_content('tags') or {}
for t in tags:
if t['tag'] == tag and t['server_id'] == ctx.message.server.id:
t['result'] = tag_result
@ -57,11 +57,11 @@ class Tags:
"I have just added the tag `{0}`! You can call this tag by entering !tag {0}".format(tag))
@tag.command(name='delete', aliases=['remove', 'stop'], pass_context=True, no_pm=True)
@checks.customPermsOrRole(kick_members=True)
@checks.custom_perms(kick_members=True)
async def del_tag(self, ctx, *, tag: str):
"""Use this to remove a tag that from use for this server
Format to delete a tag is !tag delete <tag>"""
tags = config.getContent('tags') or {}
tags = config.get_content('tags') or {}
result = [t for t in tags if t['tag'] == tag and t['server_id'] == ctx.message.server.id]
if len(result) == 0:
await self.bot.say(

View file

@ -117,7 +117,7 @@ class TicTacToe:
def update_records(winner, loser):
matches = config.getContent('tictactoe')
matches = config.get_content('tictactoe')
if matches is None:
matches = {winner.id: "1-0", loser.id: "0-1"}
@ -155,10 +155,10 @@ class TicTacToe:
matches[winner.id] = winner_stats
matches[loser.id] = loser_stats
return config.saveContent('tictactoe', battles)
return config.save_content('tictactoe', battles)
@commands.group(pass_context=True, aliases=['tic', 'tac', 'toe'], no_pm=True, invoke_without_command=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def tictactoe(self, ctx, *, option: str):
"""Updates the current server's tic-tac-toe board
You obviously need to be one of the players to use this
@ -228,7 +228,7 @@ class TicTacToe:
await self.bot.say(str(board))
@tictactoe.command(name='start', aliases= ['challenge','create'], pass_context=True, no_pm=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def start_game(self, ctx, player2: discord.Member):
"""Starts a game of tictactoe with another player"""
player1 = ctx.message.author

View file

@ -30,10 +30,10 @@ class Twitch:
def __init__(self, bot):
self.bot = bot
async def checkChannels(self):
async def check_channels(self):
await self.bot.wait_until_ready()
while not self.bot.is_closed:
twitch = config.getContent('twitch') or {}
twitch = config.get_content('twitch') or {}
for m_id, r in twitch.items():
url = r['twitch_url']
live = r['live']
@ -46,24 +46,24 @@ class Twitch:
twitch[m_id]['live'] = 1
fmt = "{} has just gone live! View their stream at {}".format(member.name, url)
await self.bot.send_message(server, fmt)
config.saveContent('twitch', twitch)
config.save_content('twitch', twitch)
elif live and not online:
server = discord.utils.find(lambda s: s.id == r['server_id'], self.bot.servers)
member = discord.utils.find(lambda m: m.id == m_id, server.members)
twitch[m_id]['live'] = 0
fmt = "{} has just gone offline! Catch them next time they stream at {}".format(member.name, url)
await self.bot.send_message(server, fmt)
config.saveContent('twitch', twitch)
config.save_content('twitch', twitch)
await asyncio.sleep(30)
@commands.group(no_pm=True, invoke_without_command=True, pass_context=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def twitch(self, ctx, *, member: discord.Member=None):
"""Use this command to check the twitch info of a user"""
if member is None:
member = ctx.message.author
twitch_channels = config.getContent('twitch') or {}
twitch_channels = config.get_content('twitch') or {}
result = twitch_channels.get(ctx.message.author.id)
if result is None:
await self.bot.say("{} has not saved their twitch URL yet!".format(member.name))
@ -83,7 +83,7 @@ class Twitch:
await self.bot.say("```\n{}```".format(fmt))
@twitch.command(name='add', pass_context=True, no_pm=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def add_twitch_url(self, ctx, url: str):
"""Saves your user's twitch URL"""
try:
@ -100,7 +100,7 @@ class Twitch:
"What would be the point of adding a nonexistant twitch user? Silly")
return
twitch = config.getContent('twitch') or {}
twitch = config.get_content('twitch') or {}
result = twitch.get(ctx.message.author.id)
if result is not None:
@ -108,17 +108,17 @@ class Twitch:
else:
twitch[ctx.message.author.id] = {'twitch_url': url, 'server_id': ctx.message.server.id,
'notifications_on': 1, 'live': 0}
config.saveContent('twitch', twitch)
config.save_content('twitch', twitch)
await self.bot.say("I have just saved your twitch url {}".format(ctx.message.author.mention))
@twitch.command(name='remove', aliases=['delete'], pass_context=True, no_pm=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def remove_twitch_url(self, ctx):
"""Removes your twitch URL"""
twitch = config.getContent('twitch') or {}
twitch = config.get_content('twitch') or {}
if twitch.get(ctx.message.author.id) is not None:
del twitch[ctx.message.author.id]
config.saveContent('twitch', twitch)
config.save_content('twitch', twitch)
await self.bot.say("I am no longer saving your twitch URL {}".format(ctx.message.author.mention))
else:
await self.bot.say(
@ -126,16 +126,16 @@ class Twitch:
ctx.message.author.mention))
@twitch.group(pass_context=True, no_pm=True, invoke_without_command=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def notify(self, ctx):
"""This can be used to turn notifications on or off"""
pass
@notify.command(name='on', aliases=['start,yes'], pass_context=True, no_pm=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def notify_on(self, ctx):
"""Turns twitch notifications on"""
twitch = config.getContent('twitch') or {}
twitch = config.get_content('twitch') or {}
result = twitch.get(ctx.message.author.id)
if result is None:
await self.bot.say(
@ -146,15 +146,15 @@ class Twitch:
ctx.message.author.mention))
else:
twitch[ctx.message.author.id]['notifications_on'] = 1
config.saveContent('twitch', twitch)
config.save_content('twitch', twitch)
await self.bot.say("I will notify if you go live {}, you'll get a bajillion followers I promise c:".format(
ctx.message.author.mention))
@notify.command(name='off', aliases=['stop,no'], pass_context=True, no_pm=True)
@checks.customPermsOrRole(send_messages=True)
@checks.custom_perms(send_messages=True)
async def notify_off(self, ctx):
"""Turns twitch notifications off"""
twitch = config.getContent('twitch') or {}
twitch = config.get_content('twitch') or {}
if twitch.get(ctx.message.author.id) is None:
await self.bot.say(
"I do not have your twitch URL added {}. You can save your twitch url with !twitch add".format(
@ -172,5 +172,5 @@ class Twitch:
def setup(bot):
t = Twitch(bot)
config.loop.create_task(t.checkChannels())
config.loop.create_task(t.check_channels())
bot.add_cog(Twitch(bot))

View file

@ -3,11 +3,11 @@ import discord
from . import config
def isOwner(ctx):
def is_owner(ctx):
return ctx.message.author.id in config.owner_ids
def customPermsOrRole(**perms):
def custom_perms(**perms):
def predicate(ctx):
if ctx.message.channel.is_private:
return False
@ -18,7 +18,7 @@ def customPermsOrRole(**perms):
setattr(default_perms, perm, setting)
try:
required_perm_value = config.getContent('custom_permissions')[ctx.message.server.id][
required_perm_value = config.get_content('custom_permissions')[ctx.message.server.id][
ctx.command.qualified_name]
required_perm = discord.Permissions(required_perm_value)
except KeyError:
@ -30,7 +30,7 @@ def customPermsOrRole(**perms):
return commands.check(predicate)
def isPM():
def is_pm():
def predicate(ctx):
return ctx.message.channel.is_private

View file

@ -32,7 +32,7 @@ except KeyError:
quit()
def saveContent(key: str, content):
def save_content(key: str, content):
try:
with open("config.json", "r+") as jf:
data = json.load(jf)
@ -46,7 +46,7 @@ def saveContent(key: str, content):
json.dump({key: content}, jf, indent=4)
def getContent(key: str):
def get_content(key: str):
try:
with open("config.json", "r+") as jf:
return json.load(jf)[key]