-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKirbo.py
171 lines (137 loc) · 5.61 KB
/
Kirbo.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
# bot.py
import os
import ast
from discord.ext.commands.converter import MemberConverter
import requests
import discord
from dotenv import load_dotenv
from discord.ext import commands
from discord import Color
import Helper
import sys
sys.path.insert(0,"Commands")
from Fun import FunCog
from Factions import FactionCog
from MTG import MTGCog
from Economy import EconomyCog
VERSION = 'V0.1.9'
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
GUILD = os.getenv('DISCORD_GUILD')
PINK = Color.from_rgb(255,185,209)
USER_URL="https://cataclysmapi20211218110154.azurewebsites.net/api/users/"
FACTION_URL="https://cataclysmapi20211218110154.azurewebsites.net/api/factions/"
MAPS_URL="https://cataclysmapi20211218110154.azurewebsites.net/api/maps/"
intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(command_prefix=',',intents=intents,activity=discord.Activity(type=discord.ActivityType.playing, name='LEGO Star Wars'))
bot.titan=None
@bot.event
async def on_ready():
bot.titan = bot.get_user(847989667088564244)
bot.adminChat = bot.get_channel(764867760957947934)
bot.add_cog(FunCog(bot))
# bot.add_cog(FactionCog(bot))
bot.add_cog(MTGCog(bot))
bot.add_cog(EconomyCog(bot))
print(f'{bot.user.name} has connected to Discord!')
# User Income Update Function ----------------------------------------------
from apscheduler.schedulers.background import BackgroundScheduler
# Start the scheduler
sched = BackgroundScheduler()
# Adds Faction Income, Currently Broken cause Factions had a rework.
def job_function():
users = Helper.getAllUsers()
for user in users:
faction = Helper.getUserFaction(user["id"])
if faction != None:
amount = int(faction["factionIncome"])
tokens = int(user["token"]) + amount
jsonData = {"id": user["id"], "token": tokens, "date": f"{user['date']}"}
response = requests.put(USER_URL +str(user["id"]),json=jsonData)
if(response.status_code != 204):
print(f"Something went wrong with adding Tokens to user's balance. Heres the error code: {response.status_code}")
# Schedules job_function to be run once each day
# hours = 24
# sched.add_job(job_function, 'interval', hours=hours)
# sched.start()
#Help Command --------------------------------------------------------------
bot.remove_command('help')
@bot.command("help")
async def help(ctx):
embed=discord.Embed(title="Kirbo Help",description="This bot's prefix is ','\nSome of the commands have aliases.",color=PINK)
embed.add_field(name="Fun Commands", value="about, poyo, roll, slap, shoot, finish",inline=False)
embed.add_field(name="Economy Commands",value="balance, daily, store, buy, give",inline=False)
embed.add_field(name="Faction Commands",value="All Factions commands are currently disabled!",inline=False)
embed.add_field(name="MTG Commands",value="won, stats",inline=False)
#faction, createfaction, leavefaction, invite, deposit, factionstore
await ctx.send(embed=embed)
# Moderation Commands ------------------------------------------------------------
@bot.command(name="mute")
@commands.has_role("admin")
async def mute(ctx,member:MemberConverter):
role = bot.get_guild(752023138795126856).get_role(796410893071810591)
await member.add_roles(role)
await ctx.send("Muted")
@bot.command(name="unmute")
@commands.has_role("admin")
async def unmute(ctx,member:MemberConverter):
role = bot.get_guild(752023138795126856).get_role(796410893071810591)
await member.remove_roles(role)
await ctx.send("Unmuted")
# Debugging Commands -------------------------------------------------------------
@bot.command(name="testapi")
@commands.has_role("admin")
async def testapi(ctx):
responseuser = requests.get(USER_URL)
responsestore = requests.get(FACTION_URL)
await bot.titan.send(responseuser.json())
await bot.titan.send(responsestore.json())
@bot.command(name="shutdown")
@commands.has_role("admin")
async def shutdown(ctx):
if ctx.author != bot.titan:
await ctx.send("You aren't Titan!")
return
else:
await ctx.send("Shutting down Kirbo bot!")
quit()
@bot.command(name="testmsgs")
@commands.has_role("admin")
async def testmsgs(ctx):
await bot.titan.send("Test")
await bot.adminChat.send("Test")
@bot.command("enablefactions")
@commands.has_role("admin")
async def enableFaction(ctx):
bot.add_cog(FactionCog(bot))
await ctx.send("Factions Module Enabled!")
@bot.command("disablefactions")
@commands.has_role("admin")
async def disableFaction(ctx):
bot.remove_cog('FactionCog')
await ctx.send("Factions Module Disabled!")
@bot.command("enableeconomy")
@commands.has_role("admin")
async def enableEconomy(ctx):
bot.add_cog(EconomyCog(bot))
await ctx.send("Economy Module Enabled!")
@bot.command("disableeconomy")
@commands.has_role("admin")
async def disableEconomy(ctx):
bot.remove_cog('EconomyCog')
await ctx.send("Economy Module Disabled!")
#Events ---------------------------------------------------------------------
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, commands.errors.CheckFailure):
await ctx.send('Thats an admin only command!')
await bot.titan.send(f"{error}")
@bot.event
async def on_member_remove(member):
await bot.adminChat.send(f"{member} Left")
@bot.event
async def on_member_join(member):
await bot.adminChat.send(f"{member} Joined")
await member.send(f'Welcome to the Army Gang, {member.name}. Please take a look at #rules-roles to get access to the rest of the server! If you need anything, feel free to ping Titan or Coolr.')
bot.run(TOKEN)