return await self.bot.say("{} has been set as the twitch shilling channel!".format(channel.mention)) | return await self.bot.say("{} has been set as the twitch shilling channel!".format(channel.mention)) | ||||
@bot.command(pass_context=True, visible=False) | @bot.command(pass_context=True, visible=False) | ||||
async def set_customwelcomemessage(self, ctx, *message): | |||||
async def set_customwelcomemessage(self, ctx, *, message: str): | |||||
if not owner(ctx): | if not owner(ctx): | ||||
return await self.bot.reply(self.con.no_perms_reponse, delete_after=self.con.delete_after) | return await self.bot.reply(self.con.no_perms_reponse, delete_after=self.con.delete_after) | ||||
else: | else: | ||||
self.con.serverconfig = self.con.load_config() | self.con.serverconfig = self.con.load_config() | ||||
self.con.serverconfig[ctx.message.server.id]["greets"]["custom_message"] = ' '.join(message) | |||||
self.con.serverconfig[ctx.message.server.id]["greets"]["custom_message"] = message | |||||
self.con.updateconfig() | self.con.updateconfig() | ||||
return await self.bot.say("Custom message set to '{}'".format(' '.join(message)), delete_after=10) | |||||
return await self.bot.say("Custom message set to '{}'".format(message)) | |||||
@bot.command(pass_context=True, hidden=True) | |||||
@bot.command(pass_context=True, hidden=True, aliases=["setava"]) | |||||
async def changeavatar(self, ctx, url=None): | async def changeavatar(self, ctx, url=None): | ||||
""" | """ | ||||
Usage: | Usage: | ||||
else: | else: | ||||
thing = url.strip('<>') | thing = url.strip('<>') | ||||
tempAvaFile = 'tempAva.png' | |||||
avaimg = 'avaimg.png' | |||||
async with aiohttp.get(thing) as img: | async with aiohttp.get(thing) as img: | ||||
with open(tempAvaFile, 'wb') as f: | |||||
with open(avaimg, 'wb') as f: | |||||
f.write(await img.read()) | f.write(await img.read()) | ||||
with open(tempAvaFile, 'rb') as f: | |||||
with open(avaimg, 'rb') as f: | |||||
await self.bot.edit_profile(avatar=f.read()) | await self.bot.edit_profile(avatar=f.read()) | ||||
os.remove(tempAvaFile) | |||||
os.remove(avaimg) | |||||
asyncio.sleep(2) | asyncio.sleep(2) | ||||
return await self.bot.say(":ok_hand:") | return await self.bot.say(":ok_hand:") | ||||
@bot.command(hidden=True) | |||||
@bot.command(pass_context=True, hidden=True, aliases=["nick"]) | |||||
async def changenickname(self, ctx, *nick): | |||||
if not owner(ctx): | |||||
return await self.bot.reply(self.con.no_perms_reponse, delete_after=self.con.delete_after) | |||||
else: | |||||
if ctx.message.channel.permissions_for(ctx.message.server.me).change_nickname: | |||||
await self.bot.change_nickname(ctx.message.server.me, ' '.join(nick)) | |||||
return await self.bot.say(":thumbsup:") | |||||
else: | |||||
return await self.bot.say("I don't have permission to do that :sob:", delete_after=self.con.delete_after) | |||||
@bot.command(pass_context=True, hidden=True, aliases=["setgame", "game"]) | |||||
async def changegame(self, ctx, *, game: str): | |||||
if not owner(ctx): | |||||
return await self.bot.reply(self.con.no_perms_reponse, delete_after=self.con.delete_after) | |||||
else: | |||||
if game.lower() == "none": | |||||
game_name = None | |||||
else: | |||||
game_name = discord.Game(name=game) | |||||
await self.bot.change_presence(game=game_name, afk=False) | |||||
return await self.bot.say(":ok_hand: Game set to {}".format(str(game_name))) | |||||
@bot.command(pass_context=True, hidden=True, aliases=["status"]) | |||||
async def changestatus(self, ctx, status: str): | |||||
if not owner(ctx): | |||||
return await self.bot.reply(self.con.no_perms_reponse, delete_after=self.con.delete_after) | |||||
else: | |||||
status = status.lower() | |||||
if status == 'offline' or status == 'invisible': | |||||
discordStatus = discord.Status.invisible | |||||
elif status == 'idle': | |||||
discordStatus = discord.Status.idle | |||||
elif status == 'dnd': | |||||
discordStatus = discord.Status.dnd | |||||
else: | |||||
discordStatus = discord.Status.online | |||||
await self.bot.change_presence(status=discordStatus) | |||||
await self.bot.say("**:ok:** Status set to {}".format(discordStatus)) | |||||
@bot.command(pass_context=True, hidden=True) | |||||
async def echo(self, ctx, channel, *, message: str): | |||||
if not owner(ctx): | |||||
return await self.bot.reply(self.con.no_perms_reponse, delete_after=self.con.delete_after) | |||||
else: | |||||
if ctx.message.channel_mentions: | |||||
for channel in ctx.message.channel_mentions: | |||||
await self.bot.send_message(channel, content=message) | |||||
return await self.bot.say(":point_left:") | |||||
elif channel.isdigit(): | |||||
channel = ctx.message.server.get_channel(channel) | |||||
await self.bot.send_message(channel, content=message) | |||||
return await self.bot.say(":point_left:") | |||||
else: | |||||
return await self.bot.say("You did something wrong smh") | |||||
@bot.command(pass_context=True, hidden=True) | |||||
async def restart(self, ctx): | async def restart(self, ctx): | ||||
if not owner(ctx): | if not owner(ctx): | ||||
return await self.bot.reply(self.con.no_perms_reponse, delete_after=self.con.delete_after) | return await self.bot.reply(self.con.no_perms_reponse, delete_after=self.con.delete_after) | ||||
await self.bot.logout() | await self.bot.logout() | ||||
return os.execl(sys.executable, sys.executable, *sys.argv) | return os.execl(sys.executable, sys.executable, *sys.argv) | ||||
@bot.command(hidden=True) | |||||
@bot.command(pass_context=True, hidden=True) | |||||
async def shutdown(self, ctx): | async def shutdown(self, ctx): | ||||
if not owner(ctx): | if not owner(ctx): | ||||
return await self.bot.reply(self.con.no_perms_reponse, delete_after=self.con.delete_after) | return await self.bot.reply(self.con.no_perms_reponse, delete_after=self.con.delete_after) | ||||
""" | """ | ||||
if not owner(ctx): | if not owner(ctx): | ||||
return await self.bot.reply(self.con.no_perms_reponse, delete_after=self.con.delete_after) | return await self.bot.reply(self.con.no_perms_reponse, delete_after=self.con.delete_after) | ||||
embed = discord.Embed(title="RoxBot Announcement", colour=discord.Colour(0x306f99), description=' '.join(announcement)) | |||||
embed.set_footer(text="This message has be automatically generated by a QT Roxie", | |||||
icon_url=self.bot.user.avatar_url) | |||||
for server in self.bot.servers: | |||||
await self.bot.send_message(server, embed=embed) | |||||
return await self.bot.say("Done!", delete_after=self.con.delete_after) | |||||
else: | |||||
embed = discord.Embed(title="RoxBot Announcement", colour=discord.Colour(0x306f99), description=' '.join(announcement)) | |||||
embed.set_footer(text="This message has be automatically generated by a QT Roxie", | |||||
icon_url=self.bot.user.avatar_url) | |||||
for server in self.bot.servers: | |||||
await self.bot.send_message(server, embed=embed) | |||||
return await self.bot.say("Done!", delete_after=self.con.delete_after) | |||||
def setup(Bot): | def setup(Bot): |
# Twitch Shilling Part | # Twitch Shilling Part | ||||
if blacklisted(member_b): | if blacklisted(member_b): | ||||
return | return | ||||
ts_enabled = self.con.serverconfig[member_a.server.id]["twitch_shilling"]["enabled"] | |||||
ts_enabled = self.con.serverconfig[member_a.server.id]["twitch"]["enabled"] | |||||
if ts_enabled: | if ts_enabled: | ||||
if not self.con.serverconfig[member_a.server.id]["twitch_shilling"]["whitelist"][ | |||||
if not self.con.serverconfig[member_a.server.id]["twitch"]["whitelist"][ | |||||
"enabled"] or member_a.id in \ | "enabled"] or member_a.id in \ | ||||
self.con.serverconfig[member_a.server.id]["twitch_shilling"]["whitelist"]["list"]: | |||||
self.con.serverconfig[member_a.server.id]["twitch"]["whitelist"]["list"]: | |||||
if member_a.game: | if member_a.game: | ||||
if member_a.game.type: | if member_a.game.type: | ||||
channel = discord.Object( | channel = discord.Object( | ||||
self.con.serverconfig[member_a.server.id]["twitch_shilling"]["twitch-channel"]) | |||||
self.con.serverconfig[member_a.server.id]["twitch"]["twitch-channel"]) | |||||
return await self.bot.send_message(channel, | return await self.bot.send_message(channel, | ||||
content=":video_game:** {} is live!** :video_game:\n {}\n{}".format( | content=":video_game:** {} is live!** :video_game:\n {}\n{}".format( | ||||
member_a.name, member_a.game.name, member_a.game.url)) | member_a.name, member_a.game.name, member_a.game.url)) | ||||
return await self.bot.reply("You do not have permission to do this command.", delete_after=20) | return await self.bot.reply("You do not have permission to do this command.", delete_after=20) | ||||
else: | else: | ||||
self.con.serverconfig = self.con.load_config() | self.con.serverconfig = self.con.load_config() | ||||
if not self.con.serverconfig[ctx.server.id]["twitch_shilling"]["whitelist"]["enabled"]: | |||||
self.con.serverconfig[ctx.server.id]["twitch_shilling"]["whitelist"]["enabled"] = 1 | |||||
if not self.con.serverconfig[ctx.server.id]["twitch"]["whitelist"]["enabled"]: | |||||
self.con.serverconfig[ctx.server.id]["twitch"]["whitelist"]["enabled"] = 1 | |||||
self.con.updateconfig() | self.con.updateconfig() | ||||
return await self.bot.reply("Whitelist for Twitch shilling has been enabled.") | return await self.bot.reply("Whitelist for Twitch shilling has been enabled.") | ||||
else: | else: | ||||
self.con.serverconfig[ctx.server.id]["twitch_shilling"]["whitelist"]["enabled"] = 0 | |||||
self.con.serverconfig[ctx.server.id]["twitch"]["whitelist"]["enabled"] = 0 | |||||
self.con.updateconfig() | self.con.updateconfig() | ||||
return await self.bot.reply("Whitelist for Twitch shilling has been disabled.") | return await self.bot.reply("Whitelist for Twitch shilling has been disabled.") | ||||
if option in ['+', 'add']: | if option in ['+', 'add']: | ||||
self.con.serverconfig = self.con.load_config() | self.con.serverconfig = self.con.load_config() | ||||
for user in ctx.message.mentions: | for user in ctx.message.mentions: | ||||
self.con.serverconfig[ctx.message.server.id]["twitch_shilling"]["whitelist"]["list"].append(user.id) | |||||
self.con.serverconfig[ctx.message.server.id]["twitch"]["whitelist"]["list"].append(user.id) | |||||
self.con.updateconfig() | self.con.updateconfig() | ||||
whitelist_count += 1 | whitelist_count += 1 | ||||
return await self.bot.say('{} user(s) have been added to the whitelist'.format(whitelist_count)) | return await self.bot.say('{} user(s) have been added to the whitelist'.format(whitelist_count)) | ||||
elif option in ['-', 'remove']: | elif option in ['-', 'remove']: | ||||
self.con.serverconfig = self.con.load_config() | self.con.serverconfig = self.con.load_config() | ||||
for user in ctx.message.mentions: | for user in ctx.message.mentions: | ||||
if user.id in self.con.serverconfig[ctx.message.server.id]["twitch_shilling"]["whitelist"]["list"]: | |||||
self.con.serverconfig[ctx.message.server.id]["twitch_shilling"]["whitelist"]["list"].remove(user.id) | |||||
if user.id in self.con.serverconfig[ctx.message.server.id]["twitch"]["whitelist"]["list"]: | |||||
self.con.serverconfig[ctx.message.server.id]["twitch"]["whitelist"]["list"].remove(user.id) | |||||
self.con.updateconfig() | self.con.updateconfig() | ||||
whitelist_count += 1 | whitelist_count += 1 | ||||
return await self.bot.say('{} user(s) have been removed to the whitelist'.format(whitelist_count)) | return await self.bot.say('{} user(s) have been removed to the whitelist'.format(whitelist_count)) | ||||
elif option == 'list': | elif option == 'list': | ||||
return await self.bot.say( | return await self.bot.say( | ||||
self.con.serverconfig[ctx.message.server.id]["twitch_shilling"]["whitelist"]["list"]) | |||||
self.con.serverconfig[ctx.message.server.id]["twitch"]["whitelist"]["list"]) | |||||
def setup(bot): | def setup(bot): |
'cogs.selfAssign', | 'cogs.selfAssign', | ||||
'cogs.Fun' | 'cogs.Fun' | ||||
] | ] | ||||
with open('config/config.json', 'r') as config_file: | |||||
serverconfig = json.load(config_file) |
{command_prefix}listroles | {command_prefix}listroles | ||||
""" | """ | ||||
roles = [] | roles = [] | ||||
for role in self.con.serverconfig[ctx.message.server.id]["self-assign_roles"]["roles"]: | |||||
for role in self.con.serverconfig[ctx.message.server.id]["selfAssign"]["roles"]: | |||||
for serverrole in ctx.message.server.roles: | for serverrole in ctx.message.server.roles: | ||||
if role == serverrole.id: | if role == serverrole.id: | ||||
roles.append(serverrole.name) | roles.append(serverrole.name) | ||||
.iam OverwatchPing | .iam OverwatchPing | ||||
""" | """ | ||||
self.con.serverconfig = self.con.load_config() | self.con.serverconfig = self.con.load_config() | ||||
if not self.con.serverconfig[ctx.message.server.id]["self-assign_roles"]["enabled"]: | |||||
if not self.con.serverconfig[ctx.message.server.id]["selfAssign"]["enabled"]: | |||||
return | return | ||||
user = ctx.message.author | user = ctx.message.author | ||||
if role in user.roles: | if role in user.roles: | ||||
return await self.bot.say("You already have that role.") | return await self.bot.say("You already have that role.") | ||||
if role.id in self.con.serverconfig[ctx.message.server.id]["self-assign_roles"]["roles"]: | |||||
if role.id in self.con.serverconfig[ctx.message.server.id]["selfAssign"]["roles"]: | |||||
await self.bot.add_roles(user, role) | await self.bot.add_roles(user, role) | ||||
print("{} added {} to themselves in {} on {}".format(user.display_name, role.name, ctx.message.channel, | print("{} added {} to themselves in {} on {}".format(user.display_name, role.name, ctx.message.channel, | ||||
ctx.message.server)) | ctx.message.server)) | ||||
.iamn OverwatchPing | .iamn OverwatchPing | ||||
""" | """ | ||||
self.con.serverconfig = self.con.load_config() | self.con.serverconfig = self.con.load_config() | ||||
if not self.con.serverconfig[ctx.message.server.id]["self-assign_roles"]["enabled"]: | |||||
if not self.con.serverconfig[ctx.message.server.id]["selfAssign"]["enabled"]: | |||||
return | return | ||||
user = ctx.message.author | user = ctx.message.author | ||||
if role not in server.roles: | if role not in server.roles: | ||||
return await self.bot.say("That role doesn't exist. Roles are case sensitive. ") | return await self.bot.say("That role doesn't exist. Roles are case sensitive. ") | ||||
elif role in user.roles and role.id in self.con.serverconfig[ctx.message.server.id]["self-assign_roles"]["roles"]: | |||||
elif role in user.roles and role.id in self.con.serverconfig[ctx.message.server.id]["selfAssign"]["roles"]: | |||||
await self.bot.remove_roles(user, role) | await self.bot.remove_roles(user, role) | ||||
return await self.bot.reply("{} has been successfully removed.".format(role.name)) | return await self.bot.reply("{} has been successfully removed.".format(role.name)) | ||||
elif role not in user.roles and role.id in self.con.serverconfig[ctx.message.server.id]["self-assign_roles"]["roles"]: | |||||
elif role not in user.roles and role.id in self.con.serverconfig[ctx.message.server.id]["selfAssign"]["roles"]: | |||||
return await self.bot.reply("You do not have {}.".format(role.name)) | return await self.bot.reply("You do not have {}.".format(role.name)) | ||||
else: | else: | ||||
return await self.bot.say("That role is not self-assignable.") | return await self.bot.say("That role is not self-assignable.") | ||||
if not owner(ctx): | if not owner(ctx): | ||||
return await self.bot.reply(self.con.no_perms_reponse, delete_after=self.con.delete_after) | return await self.bot.reply(self.con.no_perms_reponse, delete_after=self.con.delete_after) | ||||
else: | else: | ||||
if role.id in self.con.serverconfig[ctx.message.server.id]["self-assign_roles"]["roles"]: | |||||
if role.id in self.con.serverconfig[ctx.message.server.id]["selfAssign"]["roles"]: | |||||
return await self.bot.say("{} is already a self-assignable role.".format(role.name), delete_after=self.con.delete_after) | return await self.bot.say("{} is already a self-assignable role.".format(role.name), delete_after=self.con.delete_after) | ||||
self.con.serverconfig = self.con.load_config() | self.con.serverconfig = self.con.load_config() | ||||
self.con.serverconfig[ctx.message.server.id]["self-assign_roles"]["roles"].append(role.id) | |||||
self.con.serverconfig[ctx.message.server.id]["selfAssign"]["roles"].append(role.id) | |||||
self.con.updateconfig() | self.con.updateconfig() | ||||
return await self.bot.say('Role "{}" added'.format(str(role))) | return await self.bot.say('Role "{}" added'.format(str(role))) | ||||
return await self.bot.reply(self.con.no_perms_reponse, delete_after=self.con.delete_after) | return await self.bot.reply(self.con.no_perms_reponse, delete_after=self.con.delete_after) | ||||
else: | else: | ||||
self.con.serverconfig = self.con.load_config() | self.con.serverconfig = self.con.load_config() | ||||
if role.id in self.con.serverconfig[ctx.message.server.id]["self-assign_roles"]["roles"]: | |||||
self.con.serverconfig[ctx.message.server.id]["self-assign_roles"]["roles"].remove(role.id) | |||||
if role.id in self.con.serverconfig[ctx.message.server.id]["selfAssign"]["roles"]: | |||||
self.con.serverconfig[ctx.message.server.id]["selfAssign"]["roles"].remove(role.id) | |||||
self.con.updateconfig() | self.con.updateconfig() | ||||
return await self.bot.say('"{}" has been removed from the self-assignable roles.'.format(str(role))) | return await self.bot.say('"{}" has been removed from the self-assignable roles.'.format(str(role))) | ||||
else: | else: |
{"175285455204384768": {"greets": {"enabled": 0, "welcome-channel": "", "member-role": "", "custom-message": "", "default-message:": "Be sure to read the rules."}, "goodbyes": {"enabled": 0, "goodbye-channel": ""}, "self-assign_roles": {"enabled": 0, "roles": []}, "twitch_shilling": {"enabled": 0, "twitch-channel": "", "whitelist": {"enabled": 0, "list": []}}}, "304048071963312130": {"greets": {"enabled": 1, "welcome-channel": "", "member-role": "", "custom-message": "", "default-message:": "Be sure to read the rules."}, "goodbyes": {"enabled": 1, "goodbye-channel": ""}, "self-assign_roles": {"enabled": 1, "roles": ["307330606348632064", "308083509866659850", "308083509866659850", "308082456743903233"]}, "twitch_shilling": {"enabled": 0, "twitch-channel": "", "whitelist": {"enabled": 0, "list": []}}}} | |||||
{"175285455204384768": {"greets": {"enabled": 0, "welcome-channel": "", "member-role": "", "custom-message": "", "default-message:": "Be sure to read the rules."}, "goodbyes": {"enabled": 0, "goodbye-channel": ""}, "selfAssign": {"enabled": 0, "roles": []}, "twitch": {"enabled": 0, "twitch-channel": "", "whitelist": {"enabled": 0, "list": []}}}, "304048071963312130": {"greets": {"enabled": 0, "welcome-channel": "", "member-role": "", "custom-message": "", "default-message:": "Be sure to read the rules."}, "goodbyes": {"enabled": 0, "goodbye-channel": ""}, "selfAssign": {"enabled": 0, "roles": []}, "twitch": {"enabled": 0, "twitch-channel": "", "whitelist": {"enabled": 0, "list": []}}}} |
import json | import json | ||||
from pprint import pprint | |||||
class Config(): | class Config(): | ||||
"enabled": 0, | "enabled": 0, | ||||
"goodbye-channel": "", | "goodbye-channel": "", | ||||
}, | }, | ||||
"self-assign_roles": { | |||||
"selfAssign": { | |||||
"enabled": 0, | "enabled": 0, | ||||
"roles": [] | "roles": [] | ||||
}, | }, | ||||
"twitch_shilling": { | |||||
"twitch": { | |||||
"enabled": 0, | "enabled": 0, | ||||
"twitch-channel": "", | "twitch-channel": "", | ||||
"whitelist": { | "whitelist": { | ||||
} | } | ||||
} | } | ||||
} | } | ||||
# Serverconfig is seperate here and shouldnt cause a bug like the cogs o. | |||||
self.serverconfig = self.load_config() | self.serverconfig = self.load_config() | ||||
self.bot = bot | self.bot = bot | ||||
self.no_perms_reponse = ":no_entry_sign: You do not have permission to use this command." | self.no_perms_reponse = ":no_entry_sign: You do not have permission to use this command." | ||||
def updateconfig(self): | def updateconfig(self): | ||||
with open('config/config.json', 'w') as conf_file: | with open('config/config.json', 'w') as conf_file: | ||||
json.dump(self.serverconfig, conf_file) | json.dump(self.serverconfig, conf_file) | ||||
pprint(self.serverconfig) | |||||
def config_errorcheck(self): | def config_errorcheck(self): | ||||
# TODO: Fix so that it checks for problems in children of module settings. i.e children of 'greets' | # TODO: Fix so that it checks for problems in children of module settings. i.e children of 'greets' |
from config.config import Config | from config.config import Config | ||||
from cogs import cogs | from cogs import cogs | ||||
__version__ = '0.3.0' | |||||
__version__ = '0.3.2' | |||||
settings = configparser.ConfigParser() | settings = configparser.ConfigParser() | ||||
settings.read('config/settings.ini') | settings.read('config/settings.ini') | ||||
async def on_ready(): | async def on_ready(): | ||||
# TODO: First part needs to be moved to wait_until_ready | # TODO: First part needs to be moved to wait_until_ready | ||||
con.config_errorcheck() | con.config_errorcheck() | ||||
await bot.change_presence(game=discord.Game(name="v0.3.0_Testing"), status=discord.Status.dnd, afk=False) | |||||
print("Discord.py version: "+discord.__version__) | |||||
print("Client logged in\n") | |||||
await bot.change_presence(game=discord.Game(name=__version__), afk=False) | |||||
print("Cods loaded:") | |||||
for cog in cogs: | for cog in cogs: | ||||
bot.load_extension(cog) | bot.load_extension(cog) | ||||
print(f"{cog} Cog added") | |||||
print(discord.__version__) | |||||
print("Client logged in\n") | |||||
print("{}".format(cog)) | |||||
print("") | |||||
print("Servers I am currently in:") | print("Servers I am currently in:") | ||||
for server in bot.servers: | for server in bot.servers: | ||||
print(server) | print(server) |