Skip to content

Instantly share code, notes, and snippets.

@TheRockettek
Created March 15, 2020 13:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheRockettek/4ea5008808480dbb8cc0af90c9624b6b to your computer and use it in GitHub Desktop.
Save TheRockettek/4ea5008808480dbb8cc0af90c9624b6b to your computer and use it in GitHub Desktop.
import aiohttp
import discord
import typing
import imghdr
import os
import time
import copy
import re
from io import BytesIO
import ujson as json
from datetime import datetime
from discord.ext import commands
from rockutils import rockutils
import rethinkdb as r
with open("/home/rock/Welcomer 6.0/brokenimage.png", "rb") as _file:
errorimage = BytesIO(_file.read())
markdown = {
"users": {
"user": "Alias of user.name",
"user.mention": "User mention",
"user.name": "The users name",
"user.discriminator": "The users discriminator tag",
"user.id": "The users id",
"user.avatar": "Url of users avatar",
"user.created.timestamp": "Timestamp for when the users account was created",
"user.created.since": "String for how long a user has been on discord",
"user.joined.timestamp": "Timestamp of how long a user has been on the server",
"user.joined.since": "String for how long a user has been on the server",
"user.reputation": "Number of reputation a user has",
},
"server": {
"members": "Alias of server.members",
"server": "Alias of server.name",
"server.name": "The servers name",
"server.id": "The servers id",
"server.members": "Number of users and prefix of users on server",
"server.member.count": "Number of users who are on the server",
"server.member.prefix": "Count prefix for server.member.count",
"server.icon": "Url for the server icon",
"server.created.timestamp": "Timestamp for when server was created",
"server.created.since": "String for how long the server has existed for",
"server.splash": "Url of splash the server has (if there is one)",
"server.shard_id": "Shard Id that the server is on",
},
"invite": {
"invite.code": "Code that the invite has been assigned to",
"invite.inviter": "Name of user who created the invite",
"invite.inviter.id": "Id of user who created the invite",
"invite.uses": "How many people have used the invite",
"invite.temporary": "Boolean that specifies if the invite is temporary",
"invite.created.timestamp": "Timestamp for when it was created",
"invited.created.since": "String for how long it has been since the invite was made",
"invited.max": "Max invites for an invite. Will return 0 if it is unlimited"
}
}
def canhex(hexc):
try:
int(hexc, 16)
return True
except:
return False
async def retrieve_image(guildinfo, user, guild, cdn=False):
unform_messages = guildinfo['welcomer']['images']['message']
message = "\n".join(unform_messages)
message = rockutils.text_format(message, guild=guild, user=user, form_user=True, form_server=True)
if str(guildinfo['welcomer']['images']['colour']['text']) == "0":
guildinfo['welcomer']['images']['colour']['text'] = "FFFFFF"
if str(guildinfo['welcomer']['images']['colour']['border']) == "0":
guildinfo['welcomer']['images']['colour']['border'] = "000000"
data = {
"avatar_url": str(user.avatar_url_as(format="png", static_format="png", size=256)),
"allowed_gif": "true",
"image_data": json.dumps({
"bg": guildinfo['welcomer']['images']['background'].lower(),
"b": False,
"pb": 0,
"c": {
"bo": guildinfo['welcomer']['images']['colour']['border'],
"b": guildinfo['welcomer']['images']['colour']['text'],
"pb": guildinfo['welcomer']['images']['colour']['profile'],
"ib": "FFFFFF"
},
"a": 0,
"t": 0,
"m": message
}),
"cache": "true" if cdn else "false"
}
try:
async with aiohttp.ClientSession() as session:
async with session.post(f"http://127.0.0.1:5100/images/create", data=data) as response:
if response.status == 200:
if cdn:
j = await response.json()
return j['url']
else:
return BytesIO(await response.read())
else:
return None
except:
if cdn:
return "https://cdn.welcomer.fun/images/get/error.png"
else:
return errorimage
class Welcomer(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.name = "Welcomer"
self.desc = "Allows to do customizable welcoming when someone joins"
@commands.Cog.listener()
async def on_member_join(self, member):
await r.db("welcomer5").table("botinfo").get("joins").update({"count": r.row['count']+1}).run(self.bot.connection)
if self.bot.cache['welcomer'].get(member.guild.id):
print("in cache")
guilddata = self.bot.cache['welcomer'].get(member.guild.id)
continue_welcome = True
if "namepurge" in guilddata and not member.bot:
if guilddata['namepurge']['enabled']:
bad, dom = self.bot.regex_text(member.name, guilddata['namepurge']['filter'], return_string=True)
if bad:
continue_welcome = False
try:
await member.send(f":hammer: | You have been kicked from **{member.guild.name}**\n```Your name contains a blacklisted domain: {dom}. Please remove this to be able to join```")
except Exception as e:
print(e)
try:
await member.kick(reason=f"NamePurge: Found blacklisted {dom} in {member.name}")
except Exception as e:
print(e)
return
print(f"should continue {continue_welcome}")
if continue_welcome:
if guilddata['dm']['enabled']:
kwargs = {}
message = self.bot.strip_emotes(rockutils.text_format(guilddata['dm']['message'], guild=member.guild, user=member, form_user=True, form_server=True), member.guild.emojis)
if guilddata['dm']['embed']:
embed = discord.Embed(colour=3553599, description=message)
kwargs['embed'] = embed
else:
kwargs['content'] = message
try:
await member.send(**kwargs)
except:
pass
channel = member.guild.get_channel(int(guilddata['channel']))
if type(channel) == discord.channel.TextChannel:
useembed = False
has_invite = False
has_image = False
invite_obj = {"a":""}
image_obj = None
message = ""
if guilddata['text']['enabled']:
await r.db("welcomer5").table("botinfo").get("welcomes").update({"count": r.row['count']+1}).run(self.bot.connection)
if guilddata['text']['invited']:
invites = await self.bot.extract_invites(member.guild)
if invites != "NoPermission":
guildinfo = await self.bot.get_guild_info(member.guild.id, refer="on_member_join")
if invites != guildinfo['details']['guild']['invites']:
oldinvites = copy.deepcopy(guildinfo['details']['guild']['invites'])
print("Different")
guildinfo['details']['guild']['invites'] = invites
await self.bot.update_guild_info(member.guild.id, guildinfo)
else:
oldinvites = invites
invite_ids = list(i['code'] for i in guildinfo['details']['guild']['invites'])
changed_invites = []
message += "\n"
for invite in invites:
if not invite['code'] in invite_ids:
if invite['uses'] == 1:
changed_invites.append(invite)
else:
if invite['code'] in invite_ids:
c = list(i for i in oldinvites if i['code'] == invite['code'])
if len(c) > 0:
if invite['uses'] - c[0]['uses'] == 1:
changed_invites.append(invite)
if len(changed_invites) == 1:
has_invite = True
invite_obj = changed_invites[0]
message = self.bot.strip_emotes(rockutils.text_format(guilddata['text']['message'], guild=member.guild, user=member, invite=invite_obj, form_invite=True, form_user=True, form_server=True), member.guild.emojis)
message += "\n"
if guilddata['text']['badges']:
message += "\n"
userinfo = await self.bot.get_user_info(member.id, refer="on_member_join")
badges = await self.bot.retrieve_badges(member, userinfo)
if badges != userinfo['badges']:
userinfo['badges'] = badges
await self.bot.update_user_info(member.id, userinfo)
for badge in userinfo['badges']:
message += f"{badge[0]} - `{badge[1]}`\n"
if guilddata['images']['enabled']:
resp = await retrieve_image(
{"welcomer": guilddata},
member, member.guild,
cdn=guilddata['enable_embed'])
if type(resp) == str:
image_obj = resp
has_image = True
elif resp is not None:
image_obj = discord.File(resp, "Welcome." + imghdr.what(resp))
has_image = True
kwargs = {}
if guilddata['enable_embed']:
ekwargs = {}
ekwargs['colour'] = 3553599
# ekwargs['timestamp'] = datetime.utcfromtimestamp(time.time())
if len(message) > 0:
ekwargs['description'] = message
embed = discord.Embed(**ekwargs)
if has_image:
embed.set_image(url=image_obj)
kwargs['embed'] = embed
else:
if has_image:
kwargs['file'] = image_obj
if len(message) > 0:
kwargs['content'] = message
try:
await channel.send(**kwargs)
except Exception as e:
print(e)
@commands.group(name="welcomer", aliases=['whalecummer','welcomr'], description=":confetti_ball:")
async def welcomer(self, ctx):
if ctx.invoked_subcommand is None:
permitted = await self.bot.has_permission(ctx.author, ctx.guild, ctx.guildinfo, ctx.userinfo, server_staff=True, owner=True)
if permitted:
message = ""
for command in sorted(ctx.command.commands, key=lambda o: f"{o.full_parent_name} {o.name}"):
message += f"**{command.full_parent_name} {command.name} {command.description.split('|')[0]}** | {command.brief or command.description.split('|')[1]}\n"
await self.bot.send_data(ctx, message, ctx.userinfo, title=f"{ctx.command.name[0].upper()}{ctx.command.name[1:].lower()} usage")
else:
return await self.bot.missing_permission(ctx)
@welcomer.command(name="setchannel", aliases=['sc','channel'], description="<#>|Changes channel that welcomer uses")
async def welcomer_setchannel(self, ctx, channel:typing.Optional[discord.channel.TextChannel]=None):
if not ctx.guild:
return await ctx.send(f"{self.bot.get_emoji('cross')} | This command requires to be ran on a server")
permitted = await self.bot.has_permission(ctx.author, ctx.guild, ctx.guildinfo, ctx.userinfo, server_staff=True, owner=True)
if not permitted:
return await self.bot.missing_permission(ctx)
if not channel:
return await ctx.send(f"{self.bot.get_emoji('cross')} | No valid channel has been specified", delete_after=30)
ctx.guildinfo['welcomer']['channel'] = str(channel.id)
self.bot.cache['welcomer'][ctx.guild.id] = ctx.guildinfo['welcomer']
await self.bot.update_guild_info(ctx.guild.id, ctx.guildinfo)
return await ctx.send(f"{self.bot.get_emoji('check')} | Set channel to **{channel.name}**")
@welcomer.command(name="formatting", aliases=['markdown','text-formatting','textformatting','format'], description="|Lists all welcomer text formatting")
async def welcomer_markdown(self, ctx):
mmessage = "**Must be in the format \{key\}**\n\n"
for mark_title, mark_list in markdown.items():
mmessage += f"**{mark_title.upper()}**\n"
for mark_tag, mark_desc in mark_list.items():
message = f"{mark_tag} - `{mark_desc}`\n"
if len(message) + len(mmessage) > 2048:
await self.bot.send_data(ctx, mmessage, ctx.userinfo, title="Welcomer Text Formatting", force_guild=True)
mmessage = ""
mmessage += message
mmessage += "\n"
await self.bot.send_data(ctx, mmessage, ctx.userinfo, title=f"Welcomer Text Formatting", force_guild=True)
@welcomer.command(name="embed", aliases=['useembed'], description="<enable/disable>|Enables or disables the use of an embed when a user joins")
async def welcomer_embed(self, ctx, responce=""):
if not ctx.guild:
return await ctx.send(f"{self.bot.get_emoji('cross')} | This command requires to be ran on a server")
permitted = await self.bot.has_permission(ctx.author, ctx.guild, ctx.guildinfo, ctx.userinfo, server_staff=True, owner=True)
if not permitted:
return await self.bot.missing_permission(ctx)
value = rockutils.getselection(responce, ctx.guildinfo['welcomer']['enable_embed'])
ctx.guildinfo['welcomer']['enable_embed'] = value
self.bot.cache['welcomer'][ctx.guild.id] = ctx.guildinfo['welcomer']
await self.bot.update_guild_info(ctx.guild.id, ctx.guildinfo)
return await ctx.send(f"{self.bot.get_emoji('check')} | Embed welcome messages are now **{'enabled' if ctx.guildinfo['welcomer']['enable_embed'] else 'disabled'}**")
# add
# remove
@welcomer.group(name="namepurge", description="|Manages welcomer name purging")
async def welcomer_namepurge(self, ctx):
if str(ctx.invoked_subcommand) == "welcomer namepurge":
permitted = await self.bot.has_permission(ctx.author, ctx.guild, ctx.guildinfo, ctx.userinfo, server_staff=True, owner=True)
if permitted:
message = ""
for command in sorted(ctx.command.commands, key=lambda o: f"{o.full_parent_name} {o.name}"):
message += f"**{command.full_parent_name} {command.name} {command.description.split('|')[0]}** | {command.brief or command.description.split('|')[1]}\n"
await self.bot.send_data(ctx, message, ctx.userinfo, title=f"{ctx.command.name[0].upper()}{ctx.command.name[1:].lower()} usage")
else:
return await self.bot.missing_permission(ctx)
@welcomer_namepurge.command(name="enable", aliases=['e'], description="|Enables name blacklisting on join")
async def welcomer_namepurge_enable(self, ctx):
if not ctx.guild:
return await ctx.send(f"{self.bot.get_emoji('cross')} | This command requires to be ran on a server")
permitted = await self.bot.has_permission(ctx.author, ctx.guild, ctx.guildinfo, ctx.userinfo, server_staff=True, owner=True)
if not permitted:
return await self.bot.missing_permission(ctx)
ctx.guildinfo['welcomer']['namepurge']['enabled'] = True
self.bot.cache['welcomer'][ctx.guild.id] = ctx.guildinfo['welcomer']
await self.bot.update_guild_info(ctx.guild.id, ctx.guildinfo)
return await ctx.send(f"{self.bot.get_emoji('check')} | Name purging is now **enabled**")
@welcomer_namepurge.command(name="disable", aliases=['off','d'], description="|Disables name blacklisting on join")
async def welcomer_namepurge_disable(self, ctx):
if not ctx.guild:
return await ctx.send(f"{self.bot.get_emoji('cross')} | This command requires to be ran on a server")
permitted = await self.bot.has_permission(ctx.author, ctx.guild, ctx.guildinfo, ctx.userinfo, server_staff=True, owner=True)
if not permitted:
return await self.bot.missing_permission(ctx)
ctx.guildinfo['welcomer']['namepurge']['enabled'] = False
self.bot.cache['welcomer'][ctx.guild.id] = ctx.guildinfo['welcomer']
await self.bot.update_guild_info(ctx.guild.id, ctx.guildinfo)
return await ctx.send(f"{self.bot.get_emoji('check')} | Name purging is now **disabled**")
@welcomer_namepurge.command(name="list", aliases=['ls','filterlist','filter','rules','listrules','rulelist'], description="|Lists all domains that are filtered")
async def welcomer_namepurge_list(self, ctx):
if not ctx.guild:
return await ctx.send(f"{self.bot.get_emoji('cross')} | This command requires to be ran on a server")
permitted = await self.bot.has_permission(ctx.author, ctx.guild, ctx.guildinfo, ctx.userinfo, server_staff=True, owner=True)
if not permitted:
return await self.bot.missing_permission(ctx)
message = ""
sub_message = ""
for number, rule in enumerate(ctx.guildinfo['welcomer']['namepurge']['filter']):
sub_message = f"**{number+1}**) {rule}\n"
if len(message) + len(sub_message) > 2048:
await self.bot.send_data(ctx, message, ctx.userinfo, raw=False, title="Namepurge filter", force_guild=True, force_dm=False, alert=False)
message = ""
message += sub_message
await self.bot.send_data(ctx, message, ctx.userinfo, raw=False, title="Namepurge filter", force_guild=True, force_dm=False, alert=False)
@welcomer_namepurge.command(name="add", aliases=['a','addrule','new'], description="...|Adds a domain from the name filter")
async def welcomer_namepurge_add(self, ctx, *, text=None):
if not ctx.guild:
return await ctx.send(f"{self.bot.get_emoji('cross')} | This command requires to be ran on a server")
permitted = await self.bot.has_permission(ctx.author, ctx.guild, ctx.guildinfo, ctx.userinfo, server_staff=True, owner=True)
if not permitted:
return await self.bot.missing_permission(ctx)
if not text:
return await ctx.send(f"{self.bot.get_emoji('cross')} | No domain was provided", delete_after=30)
if text in ctx.guildinfo['welcomer']['namepurge']['filter']:
return await ctx.send(f"{self.bot.get_emoji('cross')} | This domain is already blacklisted", delete_after=30)
ctx.guildinfo['welcomer']['namepurge']['filter'].append(text)
self.bot.cache['welcomer'][ctx.guild.id] = ctx.guildinfo['welcomer']
await self.bot.update_guild_info(ctx.guild.id, ctx.guildinfo)
return await ctx.send(f"{self.bot.get_emoji('check')} | Added domain block for **{text}**")
@welcomer_namepurge.command(name="remove", aliases=['delete','r','removerule','deleterule'], description="<number>|Removes a domain from the name filter")
async def welcomer_namepurge_remove(self, ctx, *, text=None):
if not ctx.guild:
return await ctx.send(f"{self.bot.get_emoji('cross')} | This command requires to be ran on a server")
permitted = await self.bot.has_permission(ctx.author, ctx.guild, ctx.guildinfo, ctx.userinfo, server_staff=True, owner=True)
if not permitted:
return await self.bot.missing_permission(ctx)
if not text:
return await ctx.send(f"{self.bot.get_emoji('cross')} | No domain was provided", delete_after=30)
if not text in ctx.guildinfo['welcomer']['namepurge']['filter']:
return await ctx.send(f"{self.bot.get_emoji('cross')} | Could not find this domain on the domain block list", delete_after=30)
ctx.guildinfo['welcomer']['namepurge']['filter'].remove(text)
self.bot.cache['welcomer'][ctx.guild.id] = ctx.guildinfo['welcomer']
await self.bot.update_guild_info(ctx.guild.id, ctx.guildinfo)
return await ctx.send(f"{self.bot.get_emoji('check')} | Removed domain block for **{text}**")
@welcomer.group(name="text", description="|Manages welcoming text")
async def welcomer_text(self, ctx):
if str(ctx.invoked_subcommand) == "welcomer text":
permitted = await self.bot.has_permission(ctx.author, ctx.guild, ctx.guildinfo, ctx.userinfo, server_staff=True, owner=True)
if permitted:
message = ""
for command in sorted(ctx.command.commands, key=lambda o: f"{o.full_parent_name} {o.name}"):
message += f"**{command.full_parent_name} {command.name} {command.description.split('|')[0]}** | {command.brief or command.description.split('|')[1]}\n"
await self.bot.send_data(ctx, message, ctx.userinfo, title=f"{ctx.command.name[0].upper()}{ctx.command.name[1:].lower()} usage")
else:
return await self.bot.missing_permission(ctx)
@welcomer_text.command(name="enable", aliases=['e'], description="|Allows welcome text messages when a user joins")
async def welcomer_text_enable(self, ctx):
if not ctx.guild:
return await ctx.send(f"{self.bot.get_emoji('cross')} | This command requires to be ran on a server")
permitted = await self.bot.has_permission(ctx.author, ctx.guild, ctx.guildinfo, ctx.userinfo, server_staff=True, owner=True)
if not permitted:
return await self.bot.missing_permission(ctx)
if not type(ctx.guild.get_channel(int(ctx.guildinfo['welcomer']['channel']))) == discord.channel.TextChannel:
return await ctx.send(f"{self.bot.get_emoji('cross')} | The channel set is not valid. Please change it with `welcomer setchannel`", delete_after=30)
ctx.guildinfo['welcomer']['text']['enabled'] = True
self.bot.cache['welcomer'][ctx.guild.id] = ctx.guildinfo['welcomer']
await self.bot.update_guild_info(ctx.guild.id, ctx.guildinfo)
return await ctx.send(f"{self.bot.get_emoji('check')} | Welcoming text is now **enabled**")
@welcomer_text.command(name="disable", aliases=['off','d'], description="|Disables welcome text messages when a user joins")
async def welcomer_text_disable(self, ctx):
if not ctx.guild:
return await ctx.send(f"{self.bot.get_emoji('cross')} | This command requires to be ran on a server")
permitted = await self.bot.has_permission(ctx.author, ctx.guild, ctx.guildinfo, ctx.userinfo, server_staff=True, owner=True)
if not permitted:
return await self.bot.missing_permission(ctx)
ctx.guildinfo['welcomer']['text']['enabled'] = False
self.bot.cache['welcomer'][ctx.guild.id] = ctx.guildinfo['welcomer']
await self.bot.update_guild_info(ctx.guild.id, ctx.guildinfo)
return await ctx.send(f"{self.bot.get_emoji('check')} | Welcoming text is now **disabled**")
@welcomer_text.command(name="setmessage", aliases=['sn','message'], description="...|Changes message that welcome messages use")
async def welcomer_text_setmessage(self, ctx, *, message=None):
if not ctx.guild:
return await ctx.send(f"{self.bot.get_emoji('cross')} | This command requires to be ran on a server")
permitted = await self.bot.has_permission(ctx.author, ctx.guild, ctx.guildinfo, ctx.userinfo, server_staff=True, owner=True)
if not permitted:
return await self.bot.missing_permission(ctx)
if not message:
return await ctx.send(f"{self.bot.get_emoji('cross')} | No message has been specified", delete_after=30)
ctx.guildinfo['welcomer']['text']['message'] = message
self.bot.cache['welcomer'][ctx.guild.id] = ctx.guildinfo['welcomer']
await self.bot.update_guild_info(ctx.guild.id, ctx.guildinfo)
return await ctx.send(f"{self.bot.get_emoji('check')} | Changed welcomer text message")
@welcomer_text.command(name="invited", aliases=['showinvited'], description="<enable/disable>|Enables or disables showing invites in welcomer text message")
async def welcomer_text_invited(self, ctx, responce=""):
if not ctx.guild:
return await ctx.send(f"{self.bot.get_emoji('cross')} | This command requires to be ran on a server")
permitted = await self.bot.has_permission(ctx.author, ctx.guild, ctx.guildinfo, ctx.userinfo, server_staff=True, owner=True)
if not permitted:
return await self.bot.missing_permission(ctx)
value = rockutils.getselection(responce, ctx.guildinfo['welcomer']['text']['invited'])
ctx.guildinfo['welcomer']['text']['invited'] = value
self.bot.cache['welcomer'][ctx.guild.id] = ctx.guildinfo['welcomer']
await self.bot.update_guild_info(ctx.guild.id, ctx.guildinfo)
return await ctx.send(f"{self.bot.get_emoji('check')} | Welcomer text invites is now **{'enabled' if ctx.guildinfo['welcomer']['text']['invited'] else 'disabled'}**")
@welcomer_text.command(name="badges", aliases=['showbadges'], description="<enable/disable>|Enables or disables showing badges in welcomer text message")
async def welcomer_text_badges(self, ctx, responce=""):
if not ctx.guild:
return await ctx.send(f"{self.bot.get_emoji('cross')} | This command requires to be ran on a server")
permitted = await self.bot.has_permission(ctx.author, ctx.guild, ctx.guildinfo, ctx.userinfo, server_staff=True, owner=True)
if not permitted:
return await self.bot.missing_permission(ctx)
value = rockutils.getselection(responce, ctx.guildinfo['welcomer']['text']['badges'])
ctx.guildinfo['welcomer']['text']['badges'] = value
self.bot.cache['welcomer'][ctx.guild.id] = ctx.guildinfo['welcomer']
await self.bot.update_guild_info(ctx.guild.id, ctx.guildinfo)
return await ctx.send(f"{self.bot.get_emoji('check')} | Welcomer text badges is now **{'enabled' if ctx.guildinfo['welcomer']['text']['badges'] else 'disabled'}**")
@welcomer.group(name="image", description="|Manages welcoming images")
async def welcomer_image(self, ctx):
if str(ctx.invoked_subcommand) == "welcomer image":
permitted = await self.bot.has_permission(ctx.author, ctx.guild, ctx.guildinfo, ctx.userinfo, server_staff=True, owner=True)
if permitted:
message = ""
for command in sorted(ctx.command.commands, key=lambda o: f"{o.full_parent_name} {o.name}"):
message += f"**{command.full_parent_name} {command.name} {command.description.split('|')[0]}** | {command.brief or command.description.split('|')[1]}\n"
await self.bot.send_data(ctx, message, ctx.userinfo, title=f"{ctx.command.name[0].upper()}{ctx.command.name[1:].lower()} usage")
else:
return await self.bot.missing_permission(ctx)
@welcomer_image.command(name="enable", aliases=['e'], description="|Allows welcome image messages when a user joins")
async def welcomer_image_enable(self, ctx):
if not ctx.guild:
return await ctx.send(f"{self.bot.get_emoji('cross')} | This command requires to be ran on a server")
permitted = await self.bot.has_permission(ctx.author, ctx.guild, ctx.guildinfo, ctx.userinfo, server_staff=True, owner=True)
if not permitted:
return await self.bot.missing_permission(ctx)
if not type(ctx.guild.get_channel(int(ctx.guildinfo['welcomer']['channel']))) == discord.channel.TextChannel:
return await ctx.send(f"{self.bot.get_emoji('cross')} | The channel set is not valid. Please change it with `welcomer setchannel`", delete_after=30)
ctx.guildinfo['welcomer']['images']['enabled'] = True
self.bot.cache['welcomer'][ctx.guild.id] = ctx.guildinfo['welcomer']
await self.bot.update_guild_info(ctx.guild.id, ctx.guildinfo)
return await ctx.send(f"{self.bot.get_emoji('check')} | Welcoming images is now **enabled**")
@welcomer_image.command(name="disable", aliases=['off','d'], description="|Disables welcome image messages when a user joins")
async def welcomer_image_disable(self, ctx):
if not ctx.guild:
return await ctx.send(f"{self.bot.get_emoji('cross')} | This command requires to be ran on a server")
permitted = await self.bot.has_permission(ctx.author, ctx.guild, ctx.guildinfo, ctx.userinfo, server_staff=True, owner=True)
if not permitted:
return await self.bot.missing_permission(ctx)
ctx.guildinfo['welcomer']['images']['enabled'] = False
self.bot.cache['welcomer'][ctx.guild.id] = ctx.guildinfo['welcomer']
await self.bot.update_guild_info(ctx.guild.id, ctx.guildinfo)
return await ctx.send(f"{self.bot.get_emoji('check')} | Welcoming images is now **disabled**")
@welcomer_image.command(name="setresolution", aliases=['resolution','setsize','size'], description="<width=1000> <height=300>|Sets resolution that welcomer will use")
async def welcomer_image_setresolution(self, ctx, width:typing.Optional[int]=1000, height:typing.Optional[int]=300):
if not ctx.guild:
return await ctx.send(f"{self.bot.get_emoji('cross')} | This command requires to be ran on a server")
permitted = await self.bot.has_permission(ctx.author, ctx.guild, ctx.guildinfo, ctx.userinfo, server_staff=True, owner=True)
if not permitted:
return await self.bot.missing_permission(ctx)
if not [width,height] in [[1000,300],[500,600]]:
donation = await self.bot.guild_donation(ctx.guild, ctx.guildinfo, plus=True, pro=True, ext=True, part=True)
if not donation:
return await ctx.send(f"{self.bot.get_emoji('cross')} | This command requires you to have atleast **Welcomer Plus**. Find out more details by using the `donate` command", delete_after=30)
ctx.guildinfo['welcomer']['images']['resolution'] = [width, height]
self.bot.cache['welcomer'][ctx.guild.id] = ctx.guildinfo['welcomer']
await self.bot.update_guild_info(ctx.guild.id, ctx.guildinfo)
return await ctx.send(f"{self.bot.get_emoji('check')} | Welcoming images now use the resolution **{width}**x**{height}**")
@welcomer_image.command(name="setcolour", aliases=['colour'], description="<textborder/text/profile> <hex>|Sets colour for different parts of the message. ARGB or RGB is supported")
async def welcomer_image_setcolour(self, ctx, part=None, hexc=None):
defaults = {
"textborder": "FFFFFFFF",
"text": "000000",
"profile": "FFFFFF"
}
keys = {
"textborder": "border",
"text": "text",
"profile": "profile"
}
local = {
"textborder": "text border colour",
"text": "text colour",
"profile": "profile border colour"
}
if not ctx.guild:
return await ctx.send(f"{self.bot.get_emoji('cross')} | This command requires to be ran on a server")
permitted = await self.bot.has_permission(ctx.author, ctx.guild, ctx.guildinfo, ctx.userinfo, server_staff=True, owner=True)
if not permitted:
return await self.bot.missing_permission(ctx)
if not part or not part in ['textborder','text','profile']:
return await ctx.send(f"{self.bot.get_emoji('cross')} | No colour type has been specified. It can be either `textborder,text,profile`", delete_after=30)
if not hexc:
hexc = defaults.get(part)
hexc = hexc.replace("#","")
if not canhex(hexc):
return await ctx.send(f"{self.bot.get_emoji('cross')} | `#{hexc.replace('#','')}` is not a valid hexidecimal code. An example would be `#000000` or `#FFFFFFFF`. If you do not know what you are doing its recommend you change colour from the dashboard.", delete_after=30)
if not len(hexc) in [6,8]:
return await ctx.send(f"{self.bot.get_emoji('cross')} | `#{hexc.replace('#','')}` must be either ARGB (8 characters long) or RGB (6 characters long). If you do not know what you are doing its recommend you change colour from the dashboard.", delete_after=30)
if len(hexc) == 6:
hexc == f"00{hexc}"
ctx.guildinfo['welcomer']['images']['colour'][keys.get(part)] = hexc
self.bot.cache['welcomer'][ctx.guild.id] = ctx.guildinfo['welcomer']
await self.bot.update_guild_info(ctx.guild.id, ctx.guildinfo)
return await ctx.send(f"{self.bot.get_emoji('check')} | Changed {local.get(part)} to **#{hexc}**")
@welcomer_image.command(name="setmessage", aliases=['sm'], description="<line> ...|Changes a line on the welcome message")
async def welcomer_image_setmessage(self, ctx, line:typing.Optional[int]=None, *, message=""):
if not ctx.guild:
return await ctx.send(f"{self.bot.get_emoji('cross')} | This command requires to be ran on a server")
permitted = await self.bot.has_permission(ctx.author, ctx.guild, ctx.guildinfo, ctx.userinfo, server_staff=True, owner=True)
if not permitted:
return await self.bot.missing_permission(ctx)
if not line:
return await ctx.send(f"{self.bot.get_emoji('cross')} | Please specify a line number. This can either be `1,2,3`", delete_after=30)
if len(message) > 60:
return await ctx.send(f"{self.bot.get_emoji('cross')} | The message length is too long. Please make sure it is less than 60 characters `{len(message)} <= 60`", delete_after=30)
ctx.guildinfo['welcomer']['images']['message'][int(line)-1] = message
self.bot.cache['welcomer'][ctx.guild.id] = ctx.guildinfo['welcomer']
await self.bot.update_guild_info(ctx.guild.id, ctx.guildinfo)
return await ctx.send(f"{self.bot.get_emoji('check')} | Line **{line}** has been {'**cleared**' if message == '' else f'set to `{message}`'}")
@welcomer_image.command(name="setbackground", aliases=['sb','background'], description="<name>|Sets a background for welcomer to use")
async def welcomer_image_background(self, ctx, background=None):
if not ctx.guild:
return await ctx.send(f"{self.bot.get_emoji('cross')} | This command requires to be ran on a server")
permitted = await self.bot.has_permission(ctx.author, ctx.guild, ctx.guildinfo, ctx.userinfo, server_staff=True, owner=True)
if not permitted:
return await self.bot.missing_permission(ctx)
if not background:
return await ctx.send(f"{self.bot.get_emoji('cross')} | No background has been specified. You can find a complete list at **https://welcomer.fun/backgrounds**", delete_after=30)
if not os.path.exists(f"/home/rock/CDN/Images/{background.lower()}.png"):
return await ctx.send(f"{self.bot.get_emoji('cross')} | Could not find a background with this name. You can find a complete list at **https://welcomer.fun/backgrounds**", delete_after=30)
ctx.guildinfo['welcomer']['images']['background'] = background
self.bot.cache['welcomer'][ctx.guild.id] = ctx.guildinfo['welcomer']
await self.bot.update_guild_info(ctx.guild.id, ctx.guildinfo)
return await ctx.send(f"{self.bot.get_emoji('check')} | Background changed to **{background}**")
@welcomer.group(name="dm", description="|Manages welcoming dms")
async def welcomer_dm(self, ctx):
if str(ctx.invoked_subcommand) == "welcomer dm":
permitted = await self.bot.has_permission(ctx.author, ctx.guild, ctx.guildinfo, ctx.userinfo, server_staff=True, owner=True)
if permitted:
message = ""
for command in sorted(ctx.command.commands, key=lambda o: f"{o.full_parent_name} {o.name}"):
message += f"**{command.full_parent_name} {command.name} {command.description.split('|')[0]}** | {command.brief or command.description.split('|')[1]}\n"
await self.bot.send_data(ctx, message, ctx.userinfo, title=f"{ctx.command.name[0].upper()}{ctx.command.name[1:].lower()} usage")
else:
return await self.bot.missing_permission(ctx)
@welcomer_dm.command(name="enable", aliases=['e'], description="|Allows welcome dm messages when a user joins")
async def welcomer_dm_enable(self, ctx):
if not ctx.guild:
return await ctx.send(f"{self.bot.get_emoji('cross')} | This command requires to be ran on a server")
permitted = await self.bot.has_permission(ctx.author, ctx.guild, ctx.guildinfo, ctx.userinfo, server_staff=True, owner=True)
if not permitted:
return await self.bot.missing_permission(ctx)
if not type(ctx.guild.get_channel(int(ctx.guildinfo['welcomer']['channel']))) == discord.channel.TextChannel:
return await ctx.send(f"{self.bot.get_emoji('cross')} | The channel set is not valid. Please change it with `welcomer setchannel`", delete_after=30)
ctx.guildinfo['welcomer']['dm']['enabled'] = True
self.bot.cache['welcomer'][ctx.guild.id] = ctx.guildinfo['welcomer']
await self.bot.update_guild_info(ctx.guild.id, ctx.guildinfo)
return await ctx.send(f"{self.bot.get_emoji('check')} | Welcoming dm is now **enabled**")
@welcomer_dm.command(name="disable", aliases=['off','d'], description="|Disables welcome dm messages when a user joins")
async def welcomer_dm_disable(self, ctx):
if not ctx.guild:
return await ctx.send(f"{self.bot.get_emoji('cross')} | This command requires to be ran on a server")
permitted = await self.bot.has_permission(ctx.author, ctx.guild, ctx.guildinfo, ctx.userinfo, server_staff=True, owner=True)
if not permitted:
return await self.bot.missing_permission(ctx)
ctx.guildinfo['welcomer']['dm']['enabled'] = False
self.bot.cache['welcomer'][ctx.guild.id] = ctx.guildinfo['welcomer']
await self.bot.update_guild_info(ctx.guild.id, ctx.guildinfo)
return await ctx.send(f"{self.bot.get_emoji('check')} | Welcoming dm is now **disabled**")
@welcomer_dm.command(name="setmessage", aliases=['sn','message'], description="...|Changes message that welcomer dm message use")
async def welcomer_dm_setmessage(self, ctx, *, message=None):
if not ctx.guild:
return await ctx.send(f"{self.bot.get_emoji('cross')} | This command requires to be ran on a server")
permitted = await self.bot.has_permission(ctx.author, ctx.guild, ctx.guildinfo, ctx.userinfo, server_staff=True, owner=True)
if not permitted:
return await self.bot.missing_permission(ctx)
if not message:
return await ctx.send(f"{self.bot.get_emoji('cross')} | No message has been specified", delete_after=30)
ctx.guildinfo['welcomer']['dm']['message'] = message
self.bot.cache['welcomer'][ctx.guild.id] = ctx.guildinfo['welcomer']
await self.bot.update_guild_info(ctx.guild.id, ctx.guildinfo)
return await ctx.send(f"{self.bot.get_emoji('check')} | Changed welcomer dm message")
@welcomer_dm.command(name="embed", aliases=['useembed'], description="<enable/disable>|Enables or disables the use of an embed in the dm message when a user joins")
async def welcomer_dm_embed(self, ctx, responce=""):
if not ctx.guild:
return await ctx.send(f"{self.bot.get_emoji('cross')} | This command requires to be ran on a server")
permitted = await self.bot.has_permission(ctx.author, ctx.guild, ctx.guildinfo, ctx.userinfo, server_staff=True, owner=True)
if not permitted:
return await self.bot.missing_permission(ctx)
value = rockutils.getselection(responce, ctx.guildinfo['welcomer']['dm']['embed'])
ctx.guildinfo['welcomer']['dm']['embed'] = value
self.bot.cache['welcomer'][ctx.guild.id] = ctx.guildinfo['welcomer']
await self.bot.update_guild_info(ctx.guild.id, ctx.guildinfo)
return await ctx.send(f"{self.bot.get_emoji('check')} | Embeded welcome dm messages are now **{'enabled' if ctx.guildinfo['welcomer']['dm']['embed'] else 'disabled'}**")
@welcomer.command(name="test", description="|Tests what welcomer will do when someone joins")
async def test(self, ctx, cdn:bool=False):
if not ctx.guild:
return await ctx.send(f"{self.bot.get_emoji('cross')} | This command requires to be ran on a server")
permitted = await self.bot.has_permission(ctx.author, ctx.guild, ctx.guildinfo, ctx.userinfo, server_staff=True, owner=True)
if not permitted:
return await self.bot.missing_permission(ctx)
return await self.on_member_join(ctx.author)
def setup(bot):
bot.add_cog(Welcomer(bot))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment