Browse Source

twitch cog updated and commented.

tags/v1.4.0
roxie 6 years ago
parent
commit
e7efc54d06
2 changed files with 28 additions and 25 deletions
  1. +27
    -25
      cogs/twitch.py
  2. +1
    -0
      config/settings.py

+ 27
- 25
cogs/twitch.py View File

@@ -1,5 +1,4 @@
import discord
from discord.ext.commands import group
from discord.ext import commands

import checks
from config.server_config import ServerConfig
@@ -15,8 +14,8 @@ class Twitch():
"""
A cog that handles posting when users go live on Twitch
"""
def __init__(self, Bot):
self.bot = Bot
def __init__(self, bot_client):
self.bot = bot_client
self.con = ServerConfig()
self.servers = self.con.servers

@@ -36,18 +35,21 @@ class Twitch():
if ts_enabled:
if not ts_whitelist or member_a.id in \
self.servers[member_a.server.id]["twitch"]["whitelist"]["list"]:
channel = discord.Object(self.servers[member_a.server.id]["twitch"]["twitch-channel"])
return await self.bot.send_message(channel,
content=":video_game:** {} is live!** :video_game:\n{}\n{}".format(
channel = self.bot.get_channel(self.servers[member_a.server.id]["twitch"]["twitch-channel"])
return await channel.send(":video_game:** {} is live!** :video_game:\n{}\n{}".format(
member_a.name, member_a.game.name, member_a.game.url))
@group(pass_context=True, hidden=True)
@checks.is_bot_owner()
async def twitch(self, ctx):
@commands.group()
@checks.is_admin_or_mod()
async def whitelist(self, ctx):
"""Command group that handles the twitch cog's whitelist."""
if ctx.invoked_subcommand is None:
return await self.bot.say('Missing Argument')
return await ctx.send('Missing Argument')

@twitch.command(pass_context=True, hidden=True)
async def enablewhitelist(self, ctx):
@whitelist.command()
async def enable(self, ctx):
"""Enables the twitch shilling whitelist. Repeat the command to disable.
Usage:
;whitelist enable"""
self.servers = self.con.load_config()
if not self.servers[ctx.server.id]["twitch"]["whitelist"]["enabled"]:
self.servers[ctx.server.id]["twitch"]["whitelist"]["enabled"] = 1
@@ -58,37 +60,37 @@ class Twitch():
self.con.update_config(self.servers)
return await self.bot.reply("Whitelist for Twitch shilling has been disabled.")

@twitch.command(pass_context=True, hidden=True)
async def whitelistadd(self, ctx, option, *mentions):
@whitelist.command()
async def edit(self, ctx, option, mentions = None):
"""Adds or removes users to the whitelist. Exactly the same as the blacklist command in usage."""
whitelist_count = 0

if not ctx.message.mentions and option != 'list':
return await self.bot.reply("You haven't mentioned anyone to whitelist.")
return await ctx.send("You haven't mentioned anyone to whitelist.")

if option not in ['+', '-', 'add', 'remove', 'list']:
return await self.bot.say('Invalid option "%s" specified, use +, -, add, or remove' % option, expire_in=20)
return await ctx.send('Invalid option "%s" specified, use +, -, add, or remove' % option, expire_in=20)

if option in ['+', 'add']:
self.servers = self.con.load_config()
for user in ctx.message.mentions:
self.servers[ctx.message.server.id]["twitch"]["whitelist"]["list"].append(user.id)
self.con.update_config(self.servers)
whitelist_count += 1
return await self.bot.say('{} user(s) have been added to the whitelist'.format(whitelist_count))
self.con.update_config(self.servers)
return await ctx.send('{} user(s) have been added to the whitelist'.format(whitelist_count))

elif option in ['-', 'remove']:
self.servers = self.con.load_config()
for user in ctx.message.mentions:
if user.id in self.servers[ctx.message.server.id]["twitch"]["whitelist"]["list"]:
self.servers[ctx.message.server.id]["twitch"]["whitelist"]["list"].remove(user.id)
self.con.update_config(self.servers)
whitelist_count += 1
return await self.bot.say('{} user(s) have been removed to the whitelist'.format(whitelist_count))
self.con.update_config(self.servers)
return await ctx.send('{} user(s) have been removed to the whitelist'.format(whitelist_count))

elif option == 'list':
return await self.bot.say(
self.servers[ctx.message.server.id]["twitch"]["whitelist"]["list"])
return await ctx.send(self.servers[ctx.message.server.id]["twitch"]["whitelist"]["list"])


def setup(Bot):
Bot.add_cog(Twitch(Bot))
def setup(bot_client):
bot_client.add_cog(Twitch(bot_client))

+ 1
- 0
config/settings.py View File

@@ -280,6 +280,7 @@ class Settings:
self.serverconfig[ctx.guild.id]["twitch"]["channel"] = channel.id
await ctx.send("{} has been set as the twitch shilling channel!".format(channel.mention))
# Is lacking whitelist options. Might be added or might be depreciated.
# Turns out this is handled in the cog and I don't think it needs changing but may be confusing.
else:
return await ctx.send("No valid option given.")
return self.con.update_config(self.serverconfig)

Loading…
Cancel
Save