2020-03-30 14:52:48 +03:00
|
|
|
import asyncio
|
2020-03-30 19:35:01 +03:00
|
|
|
import aiohttp
|
2020-03-29 14:27:26 +03:00
|
|
|
import discord
|
|
|
|
|
import json
|
2020-03-30 14:52:48 +03:00
|
|
|
|
2020-03-30 14:39:33 +03:00
|
|
|
from redbot.core import Config, checks, commands
|
2020-03-30 14:52:48 +03:00
|
|
|
from redbot.core.utils.chat_formatting import box, humanize_list, pagify
|
2020-03-29 14:27:26 +03:00
|
|
|
|
2020-04-10 13:56:56 +03:00
|
|
|
url = 'https://raw.githubusercontent.com/Kanium/KaniumCogs/master/welcomeCog/data/embedded_message.json'
|
2020-04-26 00:29:23 +03:00
|
|
|
|
|
|
|
|
allowed_guilds = {274657393936302080, 693796372092289024, 508781789737648138}
|
2020-03-29 14:27:26 +03:00
|
|
|
|
|
|
|
|
|
2020-03-30 19:40:47 +03:00
|
|
|
async def fetchMessage():
|
2020-03-30 19:50:37 +03:00
|
|
|
async def fetch():
|
|
|
|
|
async with aiohttp.ClientSession() as session:
|
|
|
|
|
async with session.get(url) as response:
|
|
|
|
|
html = await response.text()
|
|
|
|
|
x = json.loads(str(html))
|
|
|
|
|
return x
|
|
|
|
|
return await fetch()
|
2020-03-30 19:35:01 +03:00
|
|
|
|
2020-04-26 00:29:23 +03:00
|
|
|
|
2020-03-30 19:35:01 +03:00
|
|
|
def formatMessage(jsonFormat):
|
2020-03-30 15:29:05 +03:00
|
|
|
try:
|
2020-04-26 00:29:23 +03:00
|
|
|
message = discord.Embed(title=str(jsonFormat['title']), description=''.join(
|
|
|
|
|
map(str, jsonFormat['description'])), color=int(jsonFormat['color'], 16))
|
2020-03-30 14:32:48 +03:00
|
|
|
message.set_thumbnail(url=jsonFormat['thumbnail'])
|
|
|
|
|
for field in jsonFormat['fields']:
|
2020-04-26 00:29:23 +03:00
|
|
|
if(field['id'] != 'links'):
|
|
|
|
|
message.add_field(
|
|
|
|
|
name=field['name'], value=field['value'], inline=field['inline'])
|
2020-03-30 14:32:48 +03:00
|
|
|
else:
|
2020-04-26 00:29:23 +03:00
|
|
|
message.add_field(name=field['name'], value=''.join(
|
|
|
|
|
map(str, field['value'])), inline=field['inline'])
|
2020-03-29 14:27:26 +03:00
|
|
|
|
2020-04-26 00:29:23 +03:00
|
|
|
message.set_footer(
|
|
|
|
|
text=jsonFormat['footer']['text'], icon_url=jsonFormat['footer']['icon_url'])
|
2020-03-30 14:32:48 +03:00
|
|
|
return message
|
|
|
|
|
|
2020-03-30 15:29:05 +03:00
|
|
|
except:
|
2020-04-26 00:29:23 +03:00
|
|
|
message = discord.Embed(title="Kanium", description='', color=0x3399ff)
|
|
|
|
|
message.add_field(
|
|
|
|
|
name="Welcome", value='Welcome To Kanium !', inline=True)
|
2020-03-30 15:29:05 +03:00
|
|
|
return message
|
2020-03-29 14:27:26 +03:00
|
|
|
|
2020-04-26 00:29:23 +03:00
|
|
|
|
2020-03-30 14:52:48 +03:00
|
|
|
class WelcomeCog(commands.Cog):
|
2020-03-30 14:47:48 +03:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
|
super().__init__(*args, **kwargs)
|
2020-03-30 19:40:47 +03:00
|
|
|
self.message = ''
|
2020-03-29 14:27:26 +03:00
|
|
|
|
2020-04-26 00:29:23 +03:00
|
|
|
@commands.command(name='welcomePreview', case_insensitive=False, description='Shows a preview of the welcome message')
|
2020-04-25 20:25:45 +03:00
|
|
|
async def preview(self, ctx):
|
2020-04-26 00:29:23 +03:00
|
|
|
try:
|
|
|
|
|
if ctx.guild.id not in allowed_guilds:
|
|
|
|
|
return
|
|
|
|
|
if self.message == '':
|
|
|
|
|
self.message = await fetchMessage()
|
|
|
|
|
message = formatMessage(self.message)
|
|
|
|
|
await ctx.send(content=None, embed=message)
|
|
|
|
|
except():
|
|
|
|
|
print(f'Error Occured!')
|
2020-04-25 20:25:45 +03:00
|
|
|
|
2020-03-29 14:27:26 +03:00
|
|
|
@commands.Cog.listener()
|
|
|
|
|
async def on_member_join(self, member: discord.Member):
|
2020-03-30 19:17:55 +03:00
|
|
|
try:
|
2020-03-31 15:30:25 +03:00
|
|
|
if member.guild.id not in allowed_guilds:
|
|
|
|
|
return
|
2020-03-30 19:40:47 +03:00
|
|
|
if self.message == '':
|
|
|
|
|
self.message = await fetchMessage()
|
2020-03-30 19:35:01 +03:00
|
|
|
message = formatMessage(self.message)
|
2020-03-30 19:17:55 +03:00
|
|
|
await member.send(content=None, embed=message)
|
|
|
|
|
except (discord.NotFound, discord.Forbidden):
|
2020-04-26 00:29:23 +03:00
|
|
|
print(
|
|
|
|
|
f'Error Occured! sending a dm to {member.display_name} didnt work !')
|