Skip to content

Commit

Permalink
Added more bot specific settings
Browse files Browse the repository at this point in the history
  • Loading branch information
PieTw3lve committed Jul 19, 2024
1 parent c33835b commit 232e7e2
Show file tree
Hide file tree
Showing 48 changed files with 323 additions and 317 deletions.
23 changes: 12 additions & 11 deletions src/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ def get_setting_json():
bot = {
'version': VERSION, # DO NOT CHANGE
'token': '', # BOT TOKEN (REQUIRED)
'admin_guild_id': [000000000000000000], # ADMIN COMMAND ENABLED GUILDS (OPTIONAL)
'owner_id': [], # BOT OWNER IDS (REQUIRED)
'test_guild_id': [], # APPLICATION COMMAND ENABLED GUILDS (OPTIONAL)
'wordnik_api_key': '', # WORDNIK API KEY (OPTIONAL)
}
settings = {
general = {
'database_data_dir': 'database/database.sqlite',
'command_cooldown': 5,
'embed_color': '#249EDB',
Expand Down Expand Up @@ -77,7 +78,7 @@ def get_setting_json():

json = {
'bot': bot,
'settings': settings,
'general': general,
'economy': economy,
'profile': profile,
'pokemon': pokemon,
Expand Down Expand Up @@ -138,7 +139,7 @@ def write_setting(section: str, option: str, value):
json.dump(data, openfile, indent=4)

def register_user(user: hikari.User):
db = sqlite3.connect(get_setting('settings', 'database_data_dir'))
db = sqlite3.connect(get_setting('general', 'database_data_dir'))
cursor = db.cursor()

sql = ('INSERT INTO economy(user_id, balance, total, loss, tpass, streak, date, level, experience) VALUES (?,?,?,?,?,?,?,?,?)')
Expand All @@ -150,7 +151,7 @@ def register_user(user: hikari.User):
db.close()

def verify_user(user: hikari.User):
db = sqlite3.connect(get_setting('settings', 'database_data_dir'))
db = sqlite3.connect(get_setting('general', 'database_data_dir'))
cursor = db.cursor()

cursor.execute(f'SELECT user_id FROM economy WHERE user_id = {user.id}') # moves cursor to user's id from database
Expand All @@ -176,10 +177,10 @@ def get_commands(bot: lightbulb.BotApp) -> dict:

if __name__ == '__main__':
# Generate settings.json if not found
settings = 'settings.json'
if not os.path.isfile(settings) or not os.access(settings, os.R_OK):
settingsFile = 'settings.json'
if not os.path.isfile(settingsFile) or not os.access(settingsFile, os.R_OK):
settings = get_setting_json()
with io.open(settings, 'w') as file:
with io.open(settingsFile, 'w') as file:
file.write(json.dumps(settings, indent=4))
print('Please add your bot information to settings.json')
sys.exit(0)
Expand All @@ -191,15 +192,15 @@ def get_commands(bot: lightbulb.BotApp) -> dict:

# Check if bot token is set
token = get_setting('bot', 'token')
admin_guild_id = get_setting('bot', 'admin_guild_id')
if not token:
print('Please add your bot information to settings.json')
sys.exit(0)

# Create a bot instance
bot = lightbulb.BotApp(
token=token,
default_enabled_guilds=admin_guild_id,
owner_ids=get_setting('bot', 'owner_id'),
default_enabled_guilds=get_setting('bot', 'test_guild_id'),
help_class=None,
intents=hikari.Intents.ALL,
)
Expand All @@ -211,7 +212,7 @@ async def on_started(event):
if not os.path.exists('database'):
os.makedirs('database')

db = sqlite3.connect(get_setting('settings', 'database_data_dir'))
db = sqlite3.connect(get_setting('general', 'database_data_dir'))
cursor = db.cursor()
cursor.execute('''CREATE TABLE IF NOT EXISTS economy (
user_id INTEGER,
Expand Down
24 changes: 12 additions & 12 deletions src/extensions/admin/bet.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,25 +129,25 @@ async def select_winner(self, ctx: miru.ViewContext, select: miru.TextSelect):
economy.add_money(userID, round(self.betView.blueTeam[userID] * self.betView.bPayout), False)
if len(self.betView.blueTeam) > 0:
user = await ctx.client.rest.fetch_user(self.betView.bHighID)
embed = (hikari.Embed(title=f'{self.betView.blueName} Won!', description=f'🪙 {(self.betView.bHighBet * self.betView.bPayout):,.0f} go to <@{self.betView.bHighID}> and {(self.betView.bParticipants) - 1:,} others.\n{self.betView.get_blue_overview(10)}\n‍', color=get_setting('settings', 'embed_color')))
embed = (hikari.Embed(title=f'{self.betView.blueName} Won!', description=f'🪙 {(self.betView.bHighBet * self.betView.bPayout):,.0f} go to <@{self.betView.bHighID}> and {(self.betView.bParticipants) - 1:,} others.\n{self.betView.get_blue_overview(10)}\n‍', color=get_setting('general', 'embed_color')))
embed.set_thumbnail(user.avatar_url)
else:
embed = (hikari.Embed(title=f'{self.betView.blueName} Won!', description=f'Unfortunately, no one will get paid out...', color=get_setting('settings', 'embed_color')))
embed = (hikari.Embed(title=f'{self.betView.blueName} Won!', description=f'Unfortunately, no one will get paid out...', color=get_setting('general', 'embed_color')))
case 'green':
for userID in self.betView.greenTeam.keys():
economy.add_money(userID, round(self.betView.greenTeam[userID] * self.betView.gPayout), False)
if len(self.betView.greenTeam) > 0:
user = await ctx.client.rest.fetch_user(self.betView.gHighID)
embed = (hikari.Embed(title=f'{self.betView.greenName} Won!', description=f'🪙 {(self.betView.gHighBet * self.betView.gPayout):,.0f} go to <@{self.betView.gHighID}> and {(self.betView.gParticipants - 1):,} others.\n{self.betView.get_green_overview(10)}\n‍', color=get_setting('settings', 'embed_color')))
embed = (hikari.Embed(title=f'{self.betView.greenName} Won!', description=f'🪙 {(self.betView.gHighBet * self.betView.gPayout):,.0f} go to <@{self.betView.gHighID}> and {(self.betView.gParticipants - 1):,} others.\n{self.betView.get_green_overview(10)}\n‍', color=get_setting('general', 'embed_color')))
embed.set_thumbnail(user.avatar_url)
else:
embed = (hikari.Embed(title=f'{self.betView.greenName} Won!', description=f'Unfortunately, no one will get paid out...', color=get_setting('settings', 'embed_color')))
embed = (hikari.Embed(title=f'{self.betView.greenName} Won!', description=f'Unfortunately, no one will get paid out...', color=get_setting('general', 'embed_color')))
case 'refund':
for userID in self.betView.blueTeam.keys():
economy.add_money(userID, self.betView.blueTeam[userID], False)
for userID in self.betView.greenTeam.keys():
economy.add_money(userID, self.betView.greenTeam[userID], False)
embed = hikari.Embed(title='Bets has been canceled!', description='All bets has been refunded.', color=get_setting('settings', 'embed_color'))
embed = hikari.Embed(title='Bets has been canceled!', description='All bets has been refunded.', color=get_setting('general', 'embed_color'))

embed.set_footer(text="The players' balances have been updated")
await self.message.respond(embed, reply=True)
Expand All @@ -173,28 +173,28 @@ async def callback(self, ctx: miru.ModalContext) -> None:
if verify_user(ctx.user) == None: # if user has never been register
register_user(ctx.user)
if self.amount < 1:
embed = hikari.Embed(title='Bet Error', description='Amount is not a valid number!', color=get_setting('settings', 'embed_error_color'))
embed = hikari.Embed(title='Bet Error', description='Amount is not a valid number!', color=get_setting('general', 'embed_error_color'))
await ctx.respond(embed, flags=hikari.MessageFlag.EPHEMERAL, delete_after=10)
return self.stop()
elif economy.remove_money(userID, self.amount, False) == False:
embed = hikari.Embed(title='Bet Error', description='You do not have enough money!', color=get_setting('settings', 'embed_error_color'))
embed = hikari.Embed(title='Bet Error', description='You do not have enough money!', color=get_setting('general', 'embed_error_color'))
await ctx.respond(embed, flags=hikari.MessageFlag.EPHEMERAL, delete_after=10)
return self.stop()
elif userID in self.greenTeam.keys() and not self.team:
embed = hikari.Embed(description="You can only bet on one team!", color=get_setting('settings', 'embed_error_color'))
embed = hikari.Embed(description="You can only bet on one team!", color=get_setting('general', 'embed_error_color'))
await ctx.respond(embed, flags=hikari.MessageFlag.EPHEMERAL, delete_after=10)
return self.stop()
elif userID in self.blueTeam.keys() and self.team:
embed = hikari.Embed(description="You can only bet on one team!", color=get_setting('settings', 'embed_error_color'))
embed = hikari.Embed(description="You can only bet on one team!", color=get_setting('general', 'embed_error_color'))
await ctx.respond(embed, flags=hikari.MessageFlag.EPHEMERAL, delete_after=10)
return self.stop()
else:
embed = hikari.Embed(title='Success', description=f'You added 🪙 {self.amount:,} to {"Blue" if not self.team else "Green"} for a total of 🪙 {entry + self.amount if entry is not None else self.amount:,}!', color=get_setting('settings', 'embed_success_color'))
embed = hikari.Embed(title='Success', description=f'You added 🪙 {self.amount:,} to {"Blue" if not self.team else "Green"} for a total of 🪙 {entry + self.amount if entry is not None else self.amount:,}!', color=get_setting('general', 'embed_success_color'))
await ctx.respond(embed, flags=hikari.MessageFlag.EPHEMERAL, delete_after=30)
self.valid = True
return self.stop()
except:
embed = hikari.Embed(title='Bet Error', description='Amount is not a valid number!', color=get_setting('settings', 'embed_error_color'))
embed = hikari.Embed(title='Bet Error', description='Amount is not a valid number!', color=get_setting('general', 'embed_error_color'))
await ctx.respond(embed, flags=hikari.MessageFlag.EPHEMERAL, delete_after=10)
return self.stop()

Expand All @@ -207,7 +207,7 @@ async def callback(self, ctx: miru.ModalContext) -> None:
@lightbulb.command('start-prediction', 'Initiate a live interactive bet for users to participate in.', pass_options=True)
@lightbulb.implements(lightbulb.SlashCommand)
async def bet(ctx: lightbulb.Context, blue: str, name: str, green: str, timer: int) -> None:
embed = hikari.Embed(title=f'{name} (Open)', description=f'Submissions will close in {Error().format_seconds(timer)}.', color=get_setting('settings', 'embed_color'), timestamp=datetime.now().astimezone())
embed = hikari.Embed(title=f'{name} (Open)', description=f'Submissions will close in {Error().format_seconds(timer)}.', color=get_setting('general', 'embed_color'), timestamp=datetime.now().astimezone())
embed.add_field(name=f'{blue} (Blue) 50%', value='Total Coins: 🪙 0\nPayout: 💸 0.00\nParticipants: 👥 0\nHighest Bet: 🪙 0 (<@None>)', inline=True)
embed.add_field(name=f'{green} (Green) 50%', value='Total Coins: 🪙 0\nPayout: 💸 0.00\nParticipants: 👥 0\nHighest Bet: 🪙 0 (<@None>)', inline=True)
embed.set_footer(text=f'Requested by {ctx.author.global_name}', icon=ctx.author.display_avatar_url)
Expand Down
4 changes: 2 additions & 2 deletions src/extensions/admin/broadcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ def __init__(self, channel: hikari.TextableChannel, ping: hikari.Role, image: hi
self.image = image

async def callback(self, ctx: miru.ModalContext) -> None:
embed = hikari.Embed(title=self.header.value, description=self.message.value, color=get_setting('settings', 'embed_important_color'))
embed = hikari.Embed(title=self.header.value, description=self.message.value, color=get_setting('general', 'embed_important_color'))
embed.set_image(self.image)

await ctx.bot.rest.create_message(content=self.ping.mention, channel=self.channel.id, embed=embed, role_mentions=True)

embed = hikari.Embed(title='Success!', description=f'Announcement posted to <#{self.channel.id}>!', color=get_setting('settings', 'embed_color'))
embed = hikari.Embed(title='Success!', description=f'Announcement posted to <#{self.channel.id}>!', color=get_setting('general', 'embed_color'))
await ctx.respond(embed, flags=hikari.MessageFlag.EPHEMERAL)

@plugin.command
Expand Down
4 changes: 2 additions & 2 deletions src/extensions/admin/close_poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ async def close_poll(ctx: lightbulb.Context, channel: hikari.TextableChannel, me
try:
await ctx.bot.rest.edit_message(channel=channel.id, message=message_id, components=[])
embed.description = 'Successfully closed poll!'
embed.color = get_setting('settings', 'embed_success_color')
embed.color = get_setting('general', 'embed_success_color')
except:
embed.description = 'Could not located message!'
embed.color = get_setting('settings', 'embed_error_color')
embed.color = get_setting('general', 'embed_error_color')

await ctx.respond(embed, flags=hikari.MessageFlag.EPHEMERAL)

Expand Down
4 changes: 2 additions & 2 deletions src/extensions/admin/open_poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async def callback(self, ctx: miru.ViewContext) -> None:

return

embed = hikari.Embed(description='You already voted!', color=get_setting('settings', 'embed_error_color'))
embed = hikari.Embed(description='You already voted!', color=get_setting('general', 'embed_error_color'))
await ctx.respond(embed, flags=hikari.MessageFlag.EPHEMERAL)

@plugin.command
Expand All @@ -55,7 +55,7 @@ async def poll(ctx: lightbulb.Context, title: str, description: str, image: hika
embed = hikari.Embed(
title=title,
description=description,
color=get_setting('settings', 'embed_color'),
color=get_setting('general', 'embed_color'),
timestamp=datetime.now().astimezone()
)
embed.set_image(image)
Expand Down
10 changes: 5 additions & 5 deletions src/extensions/admin/purge.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async def purge(ctx: lightbulb.Context, amount: int) -> None:
view.add_item(ConfirmButton())
view.add_item(CancelButton())

embed = hikari.Embed(title='Are you sure you want to continue the purge operation?', description='**__WARNING:__** This Action is irreversible!', color=get_setting('settings', 'embed_color'))
embed = hikari.Embed(title='Are you sure you want to continue the purge operation?', description='**__WARNING:__** This Action is irreversible!', color=get_setting('general', 'embed_color'))
await ctx.respond(embed, components=view.build(), flags=hikari.MessageFlag.EPHEMERAL)

client = ctx.bot.d.get('client')
Expand All @@ -55,9 +55,9 @@ async def purge(ctx: lightbulb.Context, amount: int) -> None:
if view.accepted is True:
await purge_messages(ctx, amount, channel)
elif view.accepted is False:
await ctx.edit_last_response(hikari.Embed(title='Cancelled', description=f'Purge operation has been cancelled.', color=get_setting('settings', 'embed_error_color')), components=[])
await ctx.edit_last_response(hikari.Embed(title='Cancelled', description=f'Purge operation has been cancelled.', color=get_setting('general', 'embed_error_color')), components=[])
else:
await ctx.edit_last_response(hikari.Embed(title='Timed out', description=f'Purge operation has been cancelled due to inactivity...', color=get_setting('settings', 'embed_error_color')), components=[])
await ctx.edit_last_response(hikari.Embed(title='Timed out', description=f'Purge operation has been cancelled due to inactivity...', color=get_setting('general', 'embed_error_color')), components=[])

async def purge_messages(ctx: lightbulb.Context, amount: int, channel: hikari.Snowflakeish) -> None:
iterator = (
Expand All @@ -68,9 +68,9 @@ async def purge_messages(ctx: lightbulb.Context, amount: int, channel: hikari.Sn
if iterator:
async for messages in iterator.chunk(100):
await ctx.bot.rest.delete_messages(channel, messages)
await ctx.edit_last_response(hikari.Embed(title='Success', description=f'Messages has been successfully deleted.', color=get_setting('settings', 'embed_success_color')), components=[])
await ctx.edit_last_response(hikari.Embed(title='Success', description=f'Messages has been successfully deleted.', color=get_setting('general', 'embed_success_color')), components=[])
else:
await ctx.edit_last_response(title='Error', description=f'Could not find any messages younger than 14 days!', color=get_setting('settings', 'embed_error_color'), components=[])
await ctx.edit_last_response(title='Error', description=f'Could not find any messages younger than 14 days!', color=get_setting('general', 'embed_error_color'), components=[])

def load(bot):
bot.add_plugin(plugin)
Loading

0 comments on commit 232e7e2

Please sign in to comment.