Python

No description

fork
loading
Files
  • main.py
  • bot
  • requirements.txt
main.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# Main Imports
import discord
import tweepy
import bot
from bot import extensions
from bot.extensions import basic
from bot.extensions import money
from bot.extensions import raffle
from bot.extensions import roles
from bot import modules
import asyncio
import pyjokes
import datetime
import os
import json
import requests
import random
import roblox


rbx = roblox.RobloxSession()

# Secondary Imports
from discord.ext import commands
from discord.utils import get
from bot.modules.universal import variables
from bot.modules.settings import settings
from bot.modules import error_handler
from bot.modules import prizes

# Variables
token = variables.token
players = {}
uptime = 0
version = "1.2.0.0"
lasttweet = ""
patch_notes = f"""
PATCH NOTES:
version {version}
`[ + ] Added a brand spanking new money system`
	Rob bank?
	Loot boxes?
	I think yea man. 
`[ + ] Added more error handlers`
`[ + ] Added new prizes`
`[ + ] Updated the command list on Github, finally`
"""


client = commands.Bot(command_prefix="!")
client.remove_command('help')
extensions = ['raffle', 'basic', 'roles', 'money']


async def count_down():
	global uptime
	uptime = 0
	while 1:
		await asyncio.sleep(1)
		uptime += 1


async def error_create(error, ctx):
	embed = discord.Embed(title="ERROR", description=error, colour=discord.Colour.red())
	await client.send_message(ctx.message.channel, embed=embed)
	await client.add_reaction(ctx.message, emoji="⛔")


async def message_create(msg, ctx, color, title=None):
	if title:
		embed = discord.Embed(title=title, description=msg, colour=color)
	else:
		embed = discord.Embed(title="PER-42", description=msg, colour=color)
	await client.send_message(ctx.message.channel, embed=embed)
	await client.add_reaction(ctx.message, emoji="✅")



async def permission(roles, perm):
	if perm == 1:
		return True
	elif perm == 2:
		if settings.roles[0] not in roles:
			return True
		else:
			return False
	elif perm == 3:
		if settings.roles[0] not in roles and settings.roles[1] not in roles:
			return True
		else:
			return False
	elif perm == 4:
		if settings.roles[0] not in roles and settings.roles[1] not in roles and settings.roles[2] not in roles:
			return True
		else:
			return False
	elif perm == 5:
		if settings.roles[0] not in roles and settings.roles[1] not in roles and settings.roles[2] not in roles and settings.roles[3] not in roles:
			return True
		else:
			return False
	elif perm == 6:
		if settings.roles[0] not in roles and settings.roles[1] not in roles and settings.roles[2] not in roles and settings.roles[3] not in roles and settings.roles[4] not in roles:
			return True
		else:
			return False
	elif perm == 7:
		if settings.roles[0] not in roles and settings.roles[1] not in roles and settings.roles[2] not in roles and settings.roles[3] not in roles and settings.roles[4] not in roles and settings.roles[5] not in roles:
			return True
		else:
			return False
	elif perm == 8:
		if settings.roles[0] not in roles and settings.roles[1] not in roles and settings.roles[2] not in roles and settings.roles[3] not in roles and settings.roles[4] not in roles and settings.roles[5] not in roles and settings.roles[6] not in roles:
			return True
		else:
			return False
	elif perm == 9:
		if settings.roles[0] not in roles and settings.roles[1] not in roles and settings.roles[2] not in roles and \
			settings.roles[3] not in roles and settings.roles[4] not in roles and settings.roles[5] not in roles and \
			settings.roles[6] not in roles and settings.roles[7] not in roles:
			return True
		else:
			return False



async def dm_check(ctx):
	if ctx.message.channel.is_private:
		return True
	else:
		return False

async def get_tweet():
	await client.wait_until_ready()
	while not client.is_closed:
			await asyncio.sleep(2)
			global lasttweet
			if settings.swtorUpdates:
				try:
					auth = tweepy.OAuthHandler(variables.conkey, variables.consec)  # Consumer Key, Consumer Secret
					auth.set_access_token(variables.tokkey, variables.toksec)  # Token key, Token Secret
					api = tweepy.API(auth)  # logs into @Natebot01
					tweet = api.user_timeline("TORCalendar", count=1)
					tweet = tweet[0]  # Gets 50 tweets from user's timeline
					if tweet.text != lasttweet and "Event" in tweet.text:
						lasttweet = tweet.text
						tweet = tweet.text.split(" ")
						tweet.remove(tweet[-1])
						tweet.remove(tweet[0])
						tweet.remove(tweet[0])
						tweet.remove(tweet[0])
						tweet = " ".join(tweet)
						embed = discord.Embed(title = "Star Wars the Old Republic Update", description = tweet,colour = discord.Colour.blue())
						await client.send_message(client.get_channel(settings.swtorUpdateChannel), "A new Star Wars the Old Republic update"
						                                                                           " has been recieved. http://www.swtor.com/eternal-throne/updates", embed=embed)
						print("Updating discord: " + tweet)
						await client.change_presence(game=discord.Game(name=tweet))
				except Exception as e:
					print(repr(e))
				await asyncio.sleep(10)

@client.event
async def on_ready():
	print("The bot is now running.")


@client.event
async def on_member_join(member):
	channel = client.get_channel("570659473266442271")
	if settings.defaultRole:
		role = get(member.guild.roles, name = settings.role)
		if role:
			await client.add_roles(member, role)
		else:
			channel = client.get_channel("203726041456443393")
			await error_create(f"There was an error adding the default role to {member.name}", channel)
	if settings.changeUsernames:
		await client.send_message(member, "Hey there. Before you can interact in the server, I'll  need to verify your ROBLOX account first.")
		await client.send_message(member, "The process is easy. I'll need your character's name first. After that, you'll be asked" +
		" to change your current blurb to the one assigned to you. Once you do so, your account should be verified and you can " + 
		"change your account back to normal. If you run into any issues with this process, simply message the server owner.")
		username = await client.wait_for_message(timeout=432000, author=member)
		try: 
			user = rbx.get_user(username.content)
		except:
			user = None
		while user == None:
			await client.send_message(member, "That wasn't a valid ROBLOX username. Try again.")
			username = await client.wait_for_message(timeout=432000, author = member)
			try: user = rbx.get_user(username.content)
			except: user = None
		await client.send_message(member, "I found the user {username.content}. Next, you'll have to change your blurb. Please change your blurb to `scriptistic is great`. No kidding. :)")
		while str.lower(user.get_blurb()) != "scriptistic is great":
			asyncio.sleep(0.5)
			print(user.get_blurb())
		await client.send_message(member, "Looks like your account has been verified. See you on the server!")
		role = get(client.server.roles, role = "Verified")
		await client.add_roles(member, role)
		await client.change_nickname(member, user)

		
@client.event
async def on_error(error, *args, **kwargs):
	await error_handler.error_report(error, "PER-42")

#@client.event
#async def on_command_error(error, ctx):
#	await error_create("That command did not process correctly. Try again.", ctx)

@client.command(pass_context=True)
async def info(ctx):
	await message_create(
		f"Thanks for asking about me {ctx.message.author.mention}! I was created by Scriptistic and am currently running version {version} for {uptime} seconds.", ctx,
		discord.Colour.gold())

@client.command(pass_context=True)
async def uptime(ctx):
	await message_create(f"I've been online for {uptime} and am on version {version}.", ctx, discord.Colour.purple())

@client.command(pass_context=True)
async def notes(ctx):
	await message_create("Thanks for asking. No one ever asks. Messaging them to you now.", ctx, discord.Colour.purple(), title="True Love? <3")
	await client.send_message(ctx.message.author, patch_notes)

@client.command(pass_context=True)
async def private(ctx):
	role = get(ctx.message.author.roles, name='private')
	if not await dm_check(ctx) and not role:
		role = get(ctx.message.server.roles, name="private")
		await client.add_roles(ctx.message.author, role)
		await message_create("Private channel established, " + ctx.message.author.mention, ctx, discord.Colour.light_grey())
	else:
		role = get(ctx.message.author.roles, name='private')
		if not role:
			await error_create("There has been an error with that. Use !bug to report a bug.", ctx)
		else:
			await client.remove_roles(ctx.message.author, role)
			await message_create("Private channel removed, " + ctx.message.author.mention, ctx, discord.Colour.light_grey())


@client.command(pass_context=True)
async def allow(ctx, item):
	if not await dm_check(ctx) and await permission(ctx.message.author.roles, 9):
		set = ", ".join(settings.editableSettings)
		if item == "changeUsernames":
			settings.changeUsernames = True
		elif item == "usernamesAreRoles":
			settings.usernamesAreRoles = True
		elif item == "allowCommands":
			settings.allowCommands = True
		elif item == "swtorUpdates":
			settings.swtorUpdates = True
		elif item == "levelSystem":
			settings.levelSystem = True
		elif item == "raffle":
			settings.raffle = True
		else:
			await error_create(f"{item} is not a valid settings.", ctx)
			await message_create(f"Here is a list of editable settings. {set}", ctx, discord.Colour.green(), title="Editable Settings")
			return
		await message_create(f"{item} has been turned on.", ctx, discord.Colour.green())
	else:
		await error_create("You don't have permission to do that.", ctx)


@client.command(pass_context=True)
async def disallow(ctx, item):
	if not await dm_check(ctx) and await permission(ctx.message.author.roles, 9):
		set = ", ".join(settings.editableSettings)
		if item == "changeUsernames":
			settings.changeUsernames = False
		elif item == "usernamesAreRoles":
			settings.usernamesAreRoles = False
		elif item == "allowCommands":
			settings.allowCommands = False
		elif item == "swtorUpdates":
			settings.swtorUpdates = False
		elif item == "levelSystem":
			settings.levelSystem = False
		elif item == "raffle":
			settings.raffle = False
			variables.raffle_ongoing = False
			variables.raffle_time = 0
			variables.raffle_reason = ""
			variables.raffle_users = ["None"]
		else:
			await error_create(f"{item} is not a valid settings.", ctx)
			await message_create(f"Here is a list of editable settings. {set}", ctx, discord.Colour.green(), title="Editable Settings")
			return
		await message_create(f"{item} has been turned off.", ctx, discord.Colour.red())
	else:
		await error_create("You don't have permission to do that.", ctx)


if __name__ == "__main__":
	for extension in extensions:
		try:
			client.load_extension(extension)
		except Exception as error:
			print(f"{extension} can not be loaded. {repr(error)}")

	client.loop.create_task(get_tweet())
	client.loop.create_task(count_down())
	client.run(token)