-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathonjoin.py
202 lines (166 loc) · 6.97 KB
/
onjoin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import discord
from .utils import checks
from discord.ext import commands
from cogs.utils.dataIO import dataIO
from __main__ import send_cmd_help
import os
class on_join:
"""Allows you to set your own server on_join message!"""
def __init__(self, bot):
self.bot = bot
self.derp = "data/on_join/wow.json"
self.loveme = dataIO.load_json(self.derp)
@checks.is_owner()
@commands.group(pass_context=True)
async def joinmsg(self, ctx):
"""Join Message - Allows you to set a message when the bot joined the server!"""
if ctx.invoked_subcommand is None:
await send_cmd_help(ctx)
@checks.is_owner()
@joinmsg.command(pass_context=True)
async def toggle(self, ctx):
"""Turn JoinMsg on or off! It's up to you..."""
if self.loveme["TOGGLE"] is False:
self.loveme["TOGGLE"] = True
dataIO.save_json(self.derp, self.loveme)
await self.bot.say("The on_join have been turned on!")
else:
self.loveme["TOGGLE"] = False
dataIO.save_json(self.derp, self.loveme)
await self.bot.say("The on_join have been turned off!")
@checks.is_owner()
@joinmsg.command(pass_context=True)
async def embedmsg(self, ctx):
"""Do you want the welcome message to be embed?"""
if self.loveme["EMB"] is False:
self.loveme["EMB"] = True
dataIO.save_json(self.derp, self.loveme)
await self.bot.say("The on_join will now be embed!")
else:
self.loveme["EMB"] = False
dataIO.save_json(self.derp, self.loveme)
await self.bot.say("The on_join will not be embed!")
@checks.is_owner()
@joinmsg.command(pass_context=True)
async def embedauthor(self, ctx):
"""If you want to see the bot has an author in the embed."""
if self.loveme["Emba"] is False:
self.loveme["Emba"] = True
dataIO.save_json(self.derp, self.loveme)
await self.bot.say("The embed message will now display the bot as an author!")
else:
self.loveme["Emba"] = False
dataIO.save_json(self.derp, self.loveme)
await self.bot.say("The embed message will now not display the bot as an author!")
@checks.is_owner()
@joinmsg.command(pass_context=True)
async def message(self, ctx, *, msg):
"""You can set the way your on_join is set!
{0} = The Joined Server
{1} = The Bot
{2} = The Bot Owner...
Default Message: Hello, {0.name}! I am, {1.user.name}! I was created by {2}!
"""
self.loveme["MESSAGE"] = msg
dataIO.save_json(self.derp, self.loveme)
await self.bot.say("Congrats, you have set your message to ```{}```".format(msg))
@checks.is_owner()
@joinmsg.command(pass_context=True)
async def setfooter(self, ctx, *, msg):
"""Allows you to set the footer message, if it's embed
{0} = The Joined Server
{1} = The Bot
{2} = The Bot Owner...
Default Message: This is your footer!
"""
self.loveme["Embf"] = msg
dataIO.save_json(self.derp, self.loveme)
await self.bot.say("Congrats, you have set your embed footer to ```{}```".format(msg))
@checks.is_owner()
@joinmsg.command(pass_context=True)
async def setname(self, ctx, *, msg):
"""Allows you to set the embed name message, if it's embed
{0} = The Joined Server
{1} = The Bot
{2} = The Bot Owner...
Default Message: Welcome to {0.name}!
"""
self.loveme["MESSAGE_TITLE"] = msg
dataIO.save_json(self.derp, self.loveme)
await self.bot.say("Congrats, you have set your embed message name to ```{}```".format(msg))
@checks.is_owner()
@joinmsg.command(pass_context=True)
async def settitle(self, ctx, *, msg):
"""Allows you to set the title message, if it's embed
{0} = The Joined Server
{1} = The Bot
{2} = The Bot Owner...
Default Message: This is your title!
"""
self.loveme["Embt"] = msg
dataIO.save_json(self.derp, self.loveme)
await self.bot.say("Congrats, you have set your embed title name to ```{}```".format(msg))
@checks.is_owner()
@joinmsg.command(pass_context=True)
async def setcolor(self, ctx, *, msg):
"""Allows you to set the embed color, if it's embed
Needs to be a color code. Example: 0xFFFFFF
"""
self.loveme["Embc"] = msg
dataIO.save_json(self.derp, self.loveme)
await self.bot.say("Congrats, you have set your embed title name to ```{}```".format(msg))
async def mowie(self, server):
owner = discord.utils.get(self.bot.get_all_members(), id=self.bot.settings.owner)
bota = self.bot
msg = self.loveme["MESSAGE"]
send = msg.format(server, bota, owner)
channel = server.default_channel
if self.loveme["TOGGLE"] is True:
print("{} has joined {}!".format(bota.user.name, server.name))
if self.loveme["EMB"]:
try:
title = self.loveme["Embt"].format(server, bota, owner)
footer = self.loveme["Embf"].format(server, bota, owner)
auth = self.loveme["Emba"]
msgname = self.loveme["MESSAGE_TITLE"].format(server, bota, owner)
try:
color = int(self.loveme["Embc"], 16)
except:
color = 0x898a8b
wow=discord.Embed(title=title, color=color)
if auth:
wow.set_author(name=bota.user.name, url=bota.user.avatar_url)
wow.add_field(name=msgname, value=send)
wow.set_footer(text=footer)
await self.bot.send_message(channel, embed=wow)
except discord.HTTPException:
await self.bot.send_message(channel, "The bot needs embed permissions")
else:
await self.bot.send_message(channel, send)
async def on_server_join(self, server):
await self.mowie(server)
def check_folders():
if not os.path.exists("data/on_join"):
print("Creating the on_join folder, so be patient...")
os.makedirs("data/on_join")
print("Finish!")
def check_files():
twentysix = "data/on_join/wow.json"
json = {
"EMB" : False,
"TOGGLE" : False,
"MESSAGE" : "Hello, {0.name}! I am, {1.user.name}! I was created by {2.user.name}!",
"Embc" : "0xFFFFFF",
"Embf" : "This is your footer!",
"Emba" : False,
"Embt" : "This is your title!",
"MESSAGE_TITLE" : "Welcome to {0.name}!"
}
if not dataIO.is_valid_json(twentysix):
print("Derp Derp Derp...")
dataIO.save_json(twentysix, json)
print("Created wow.json!")
def setup(bot):
check_folders()
check_files()
bot.add_cog(on_join(bot))