fetching format from jsonfile thats in github

This commit is contained in:
Fadi AT 2020-03-30 14:32:48 +03:00
parent 6b5a3eaf28
commit 80217fcc4e
2 changed files with 32 additions and 18 deletions

13
welcomeCog/info.json Normal file
View File

@ -0,0 +1,13 @@
{
"author": [
"Deathblade"
],
"install_msg": "May Kanuim show you the way",
"name": "Welcome",
"short": "Sends a welcome dm thats written in a specific format to the users",
"description": "Sends a welcome dm thats written in a specific format to the users",
"requirements": ["requests"],
"tags": [
"welcome"
]
}

View File

@ -1,36 +1,37 @@
import discord
from discord.ext import commands
import json
import requests
def fetchMessage():
with open('embedded_message.json') as file:
embed = requests.get("https://raw.githubusercontent.com/Kanium/KanuimCogs/master/welcomeCog/embedded_message.json").text
def fetchMessage(jsonFormat):
try:
jsonFormat = json.load(file)
print(int(jsonFormat["color"],16))
message=discord.Embed(title=str(jsonFormat["title"]), description="".join(map(str, jsonFormat["description"])), color=int(jsonFormat["color"],16))
message.set_thumbnail(url=jsonFormat["thumbnail"])
for field in jsonFormat["fields"]:
if(field["id"]!="links"):
message.add_field(name=field["name"], value=field["value"], inline=field["inline"])
message=discord.Embed(title=str(jsonFormat['title']), description=''.join(map(str, jsonFormat['description'])), color=hex(jsonFormat['color']))
message.set_thumbnail(url=jsonFormat['thumbnail'])
for field in jsonFormat['fields']:
if(field['id']!='links'):
message.add_field(name=field['name'], value=field['value'], inline=field['inline'])
else:
message.add_field(name=field["name"], value="".join(map(str,field["value"])), inline=field["inline"])
message.add_field(name=field['name'], value=''.join(map(str,field['value'])), inline=field['inline'])
message.set_footer(text=jsonFormat["footer"]["text"], icon_url=jsonFormat["footer"]["icon_url"])
message.set_footer(text=jsonFormat['footer']['text'], icon_url=jsonFormat['footer']['icon_url'])
return message
except:
return "Welcome To Kanuim !"
return 'Welcome To Kanuim !'
class WelcomeCog(commands.Cog):
def __init__(self, bot):
self.message = fetchMessage()
self.message = json.load(embed)
self.bot = bot
@commands.Cog.listener()
@commands.guild_only()
async def on_member_join(self, member: discord.Member):
try:
await member.send(content=None, embed=self.message)
message = fetchMessage(self.message)
await member.send(content=None, embed=message)
except:
print(
f'Error Occured! sending a dm to {member.display_name} didnt work !')