Made updates to add a default dictionary/list if one was not found in the config file
This commit is contained in:
parent
7fcb0738f8
commit
08518e3beb
1
bot.py
1
bot.py
|
@ -15,6 +15,7 @@ extensions = ['cogs.interaction',
|
|||
'cogs.stats',
|
||||
'cogs.playlist',
|
||||
'cogs.twitch',
|
||||
'cogs.picarto',
|
||||
'cogs.overwatch',
|
||||
'cogs.links',
|
||||
'cogs.tags',
|
||||
|
|
|
@ -35,7 +35,7 @@ class Mod:
|
|||
@checks.customPermsOrRole(kick_members=True)
|
||||
async def nsfw_add(self, ctx):
|
||||
"""Registers this channel as a 'nsfw' channel"""
|
||||
nsfw_channels = config.getContent('nsfw_channels')
|
||||
nsfw_channels = config.getContent('nsfw_channels') or {}
|
||||
if ctx.message.channel.id in nsfw_channels:
|
||||
await self.bot.say("This channel is already registered as 'nsfw'!")
|
||||
else:
|
||||
|
@ -47,7 +47,7 @@ class Mod:
|
|||
@checks.customPermsOrRole(kick_members=True)
|
||||
async def nsfw_remove(self, ctx):
|
||||
"""Removes this channel as a 'nsfw' channel"""
|
||||
nsfw_channels = config.getContent('nsfw_channels')
|
||||
nsfw_channels = config.getContent('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:
|
||||
|
@ -144,7 +144,7 @@ class Mod:
|
|||
"""Removes the custom permissions setup on the command specified"""
|
||||
cmd = " ".join(command)
|
||||
custom_perms = config.getContent('custom_permissions') or {}
|
||||
server_perms = custom_perms.get(ctx.message.server.id)
|
||||
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!")
|
||||
return
|
||||
|
|
|
@ -33,7 +33,9 @@ class Overwatch:
|
|||
Provide a hero after the member to get stats for that specific hero"""
|
||||
if user is None:
|
||||
user = ctx.message.author
|
||||
bt = config.getContent('overwatch').get(user.id)
|
||||
|
||||
ow_stats = config.getContent('overwatch') or {}
|
||||
bt = ow_stats.get(user.id)
|
||||
|
||||
if bt is None:
|
||||
await self.bot.say("I do not have this user's battletag saved!")
|
||||
|
@ -91,7 +93,7 @@ class Overwatch:
|
|||
"format needs to be `user#xxxx`. Capitalization matters")
|
||||
return
|
||||
|
||||
ow = config.getContent('overwatch')
|
||||
ow = config.getContent('overwatch') or {}
|
||||
ow[ctx.message.author.id] = bt
|
||||
if config.saveContent('overwatch', ow):
|
||||
await self.bot.say("I have just saved your battletag {}".format(ctx.message.author.mention))
|
||||
|
@ -102,7 +104,7 @@ class Overwatch:
|
|||
@checks.customPermsOrRole(send_messages=True)
|
||||
async def delete(self, ctx):
|
||||
"""Removes your battletag from the records"""
|
||||
result = config.getContent('overwatch')
|
||||
result = config.getContent('overwatch') or {}
|
||||
if result.get(ctx.message.author.id):
|
||||
del result[ctx.message.author.id]
|
||||
if config.saveContent('overwatch', result):
|
||||
|
|
|
@ -3,7 +3,6 @@ import json
|
|||
import asyncio
|
||||
import discord
|
||||
import re
|
||||
import traceback
|
||||
|
||||
from discord.ext import commands
|
||||
from .utils import config
|
||||
|
|
|
@ -151,18 +151,18 @@ class Music:
|
|||
if state.songs.full():
|
||||
await self.bot.say("The queue is currently full! You'll need to wait to add a new song")
|
||||
return
|
||||
|
||||
|
||||
author_channel = ctx.message.author.voice.voice_channel
|
||||
my_channel = ctx.message.server.me.voice.voice_channel
|
||||
|
||||
|
||||
if my_channel != author_channel:
|
||||
await self.bot.say("You are not currently in the channel; please join before trying to request a song.")
|
||||
return
|
||||
|
||||
|
||||
try:
|
||||
player = await state.voice.create_ytdl_player(song, ytdl_options=state.opts, after=state.toggle_next)
|
||||
except youtube_dl.DownloadError:
|
||||
await self.bot.send_message(ctx.message.channel,"Sorry, that's not a supported URL!")
|
||||
await self.bot.send_message(ctx.message.channel, "Sorry, that's not a supported URL!")
|
||||
return
|
||||
player.volume = 0.6
|
||||
entry = VoiceEntry(ctx.message, player)
|
||||
|
@ -217,20 +217,21 @@ class Music:
|
|||
await state.voice.disconnect()
|
||||
except:
|
||||
pass
|
||||
|
||||
@commands.command(pass_context=True, no_pm=True)
|
||||
@checks.customPermsOrRole(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)
|
||||
author = ctx.message.author
|
||||
|
||||
|
||||
if not state.is_playing():
|
||||
await self.bot.say('Not playing any music right now...')
|
||||
return
|
||||
if len(state.songs._queue) == 0:
|
||||
await self.bot.say("Nothing currently in the queue")
|
||||
return
|
||||
|
||||
|
||||
count = state.current.player.duration
|
||||
found = False
|
||||
for song in state.songs._queue:
|
||||
|
@ -245,7 +246,7 @@ class Music:
|
|||
await self.bot.say("You are not in the queue!")
|
||||
return
|
||||
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)
|
||||
async def queue(self, ctx):
|
||||
|
|
|
@ -14,7 +14,7 @@ class Stats:
|
|||
@checks.customPermsOrRole(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')
|
||||
boops = config.getContent('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
|
||||
|
@ -51,7 +51,7 @@ class Stats:
|
|||
@checks.customPermsOrRole(send_messages=True)
|
||||
async def leaderboard(self, ctx):
|
||||
"""Prints a leaderboard of everyone in the server's battling record"""
|
||||
battles = config.getContent('battle_records')
|
||||
battles = config.getContent('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}
|
||||
|
@ -73,7 +73,7 @@ class Stats:
|
|||
"""Prints the battling stats for you, or the user provided"""
|
||||
member = member or ctx.message.author
|
||||
|
||||
all_members = config.getContent('battle_records')
|
||||
all_members = config.getContent('battle_records') or {}
|
||||
if member.id not in all_members:
|
||||
await self.bot.say("That user has not battled yet!")
|
||||
return
|
||||
|
|
|
@ -14,7 +14,7 @@ class Tags:
|
|||
@checks.customPermsOrRole(send_messages=True)
|
||||
async def tags(self, ctx):
|
||||
"""Prints all the custom tags that this server currently has"""
|
||||
tags = config.getContent('tags')
|
||||
tags = config.getContent('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))
|
||||
|
||||
|
@ -23,7 +23,7 @@ class Tags:
|
|||
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')
|
||||
tags = config.getContent('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!')
|
||||
|
@ -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')
|
||||
tags = config.getContent('tags') or {}
|
||||
for t in tags:
|
||||
if t['tag'] == tag and t['server_id'] == ctx.message.server.id:
|
||||
t['result'] = tag_result
|
||||
|
@ -67,7 +67,7 @@ class Tags:
|
|||
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')
|
||||
tags = config.getContent('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(
|
||||
|
|
|
@ -33,7 +33,7 @@ class Twitch:
|
|||
async def checkChannels(self):
|
||||
await self.bot.wait_until_ready()
|
||||
while not self.bot.is_closed:
|
||||
twitch = config.getContent('twitch')
|
||||
twitch = config.getContent('twitch') or {}
|
||||
for m_id, r in twitch.items():
|
||||
url = r['twitch_url']
|
||||
live = r['live']
|
||||
|
@ -115,7 +115,7 @@ class Twitch:
|
|||
@checks.customPermsOrRole(send_messages=True)
|
||||
async def remove_twitch_url(self, ctx):
|
||||
"""Removes your twitch URL"""
|
||||
twitch = config.getContent('twitch')
|
||||
twitch = config.getContent('twitch') or {}
|
||||
if twitch.get(ctx.message.author.id) is not None:
|
||||
del twitch[ctx.message.author.id]
|
||||
config.saveContent('twitch', twitch)
|
||||
|
@ -135,7 +135,7 @@ class Twitch:
|
|||
@checks.customPermsOrRole(send_messages=True)
|
||||
async def notify_on(self, ctx):
|
||||
"""Turns twitch notifications on"""
|
||||
twitch = config.getContent('twitch')
|
||||
twitch = config.getContent('twitch') or {}
|
||||
result = twitch.get(ctx.message.author.id)
|
||||
if result is None:
|
||||
await self.bot.say(
|
||||
|
@ -154,7 +154,7 @@ class Twitch:
|
|||
@checks.customPermsOrRole(send_messages=True)
|
||||
async def notify_off(self, ctx):
|
||||
"""Turns twitch notifications off"""
|
||||
twitch = config.getContent('twitch')
|
||||
twitch = config.getContent('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(
|
||||
|
|
|
@ -23,6 +23,8 @@ def customPermsOrRole(**perms):
|
|||
required_perm = discord.Permissions(required_perm_value)
|
||||
except KeyError:
|
||||
required_perm = default_perms
|
||||
except TypeError:
|
||||
required_perm = default_perms
|
||||
return member_perms >= required_perm
|
||||
|
||||
return commands.check(predicate)
|
||||
|
|
Loading…
Reference in a new issue