Skip to content

Commit

Permalink
Added fishing game and other changes
Browse files Browse the repository at this point in the history
  • Loading branch information
PieTw3lve committed Jul 31, 2024
1 parent d11a00b commit 280921f
Show file tree
Hide file tree
Showing 38 changed files with 1,874 additions and 1,487 deletions.
Binary file added src/assets/img/general/profile/palette.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
143 changes: 9 additions & 134 deletions src/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,140 +10,19 @@

from lightbulb.ext import tasks

VERSION = '1.3.3'
from utils.general.config import VERSION, get_setting_json, update_settings, get_setting, write_setting

## Functions ##

def install(package):
subprocess.check_call([sys.executable, '-m', 'pip', 'install', package])

def get_setting_json():
bot = {
'version': VERSION, # DO NOT CHANGE
'token': '', # BOT TOKEN (REQUIRED)
'owner_id': [], # BOT OWNER IDS (REQUIRED)
'test_guild_id': [], # APPLICATION COMMAND ENABLED GUILDS (OPTIONAL)
'wordnik_api_key': '', # WORDNIK API KEY (OPTIONAL)
}
general = {
'database_data_dir': 'database/database.sqlite',
'command_cooldown': 5,
'embed_color': '#249EDB',
'embed_important_color': 'b03f58',
'embed_success_color': '#32CD32',
'embed_error_color': '#FF0000',
'auto_translate_conf': 0.80,
'auto_translate_min_relative_distance': 0.90,
}
economy = {
'starting_balance': 300,
'starting_tux_pass': 0,
'daily_max_streak': 30,
}
profile = {
'coin': {
'gray-banner': 200,
'float-nametag': 200,
'separator-nametag': 200,
'tuxedo-nametag': 200,
'apple-base': 500,
'burgundy-base': 500,
'blueberry-base': 500,
'grape-base': 500,
'snow-base': 1000,
'snow-nametag': 1000,
'plastic-banner': 1000,
'plastic-base': 1000,
'plastic-nametag': 1000,
'blue-banner': 2000,
'orange-banner': 2000,
'grassiant-banner': 5000,
'sky-banner': 5000,
'purp-banner': 5000,
'purp-base': 5000,
'purp-nametag': 5000,
'charged_rose-banner': 5000,
'rushsite_s3-banner': 7000,
'france-banner': 10000,
'usa-banner': 10000,
},
'tpass': {
'nippuwu-banner': 1,
}
}
pokemon = {
'pokemon_pack_amount': 7,
'pokemon_max_capacity': 2000,
}

json = {
'bot': bot,
'general': general,
'economy': economy,
'profile': profile,
'pokemon': pokemon,
}

return json

def update_settings():
settings = get_setting_json()
with open('settings.json', 'r') as openfile:
data = json.load(openfile)

# Add or update settings
for section in settings:
if section not in data:
data[section] = settings[section]
else:
for option in settings[section]:
if option not in data[section]:
data[section][option] = settings[section][option]

# Remove settings not present in get_setting_json()
sections_to_remove = [section for section in data if section not in settings]
for section in sections_to_remove:
del data[section]

for section in data:
options_to_remove = [option for option in data[section] if option not in settings[section]]
for option in options_to_remove:
del data[section][option]

with open('settings.json', 'w') as openfile:
json.dump(data, openfile, indent=4)

def get_setting(section: str, option: str = None):
with open('settings.json', 'r') as openfile:
data = json.load(openfile)
if option:
if section in data and option in data[section]:
return data[section][option]
else:
return None
elif section in data:
return data[section]
else:
return None

def write_setting(section: str, option: str, value):
with open('settings.json', 'r') as openfile:
data = json.load(openfile)

if section not in data:
data[section] = {}

data[section][option] = value

with open('settings.json', 'w') as openfile:
json.dump(data, openfile, indent=4)

def register_user(user: hikari.User):
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 (?,?,?,?,?,?,?,?,?)')
val = (user.id, get_setting('economy', 'starting_balance'), get_setting('economy', 'starting_balance'), 0, get_setting('economy', 'starting_tux_pass'), 0, None, 0, 0)
sql = ('INSERT INTO economy(user_id, balance, total, loss, tpass, streak, date) VALUES (?,?,?,?,?,?,?)')
val = (user.id, get_setting('economy', 'starting_balance'), get_setting('economy', 'starting_balance'), 0, get_setting('economy', 'starting_tux_pass'), 0, None)
cursor.execute(sql, val)

db.commit() # saves changes
Expand Down Expand Up @@ -223,23 +102,19 @@ async def on_started(event):
streak INTEGER,
date TEXT
)''')
cursor.execute('''CREATE TABLE IF NOT EXISTS pokemon (
id TEXT PRIMARY KEY,
user_id TEXT,
date TEXT,
name TEXT,
pokemon_id INTEGER,
rarity INTEGER,
shiny INTEGER,
favorite INTEGER
)''')
cursor.execute('''CREATE TABLE IF NOT EXISTS profile (
user_id TEXT,
name TEXT,
type TEXT,
active INTEGER,
PRIMARY KEY (user_id, type, name)
)''')
cursor.execute('''CREATE TABLE IF NOT EXISTS fishing (
user_id TEXT,
bait_id TEXT,
amount INTEGER,
PRIMARY KEY (user_id, bait_id)
)''')

# Install uvloop for Linux users
if os.name != 'nt':
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/economy/daily.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import lightbulb
import random

from datetime import datetime, timedelta
from datetime import datetime

from bot import get_setting, verify_user, register_user
from utils.daily.manager import DailyManager
Expand Down
8 changes: 7 additions & 1 deletion src/extensions/economy/update.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import typing as t
import hikari
import lightbulb
import sqlite3

from lightbulb.ext import tasks
from lightbulb.ext.tasks import CronTrigger
from datetime import datetime

from bot import get_setting
Expand All @@ -11,7 +13,7 @@
leaderboardEco = []
leaderboardEcoLastRefresh = None

@tasks.task(m=30, auto_start=True)
@tasks.task(CronTrigger("0,30 * * * *"), auto_start=True)
async def update_leaderboard():
global leaderboardEco, leaderboardEcoLastRefresh
leaderboardEco = []
Expand Down Expand Up @@ -48,6 +50,10 @@ async def update_leaderboard():
cursor.close()
db.close()

@plugin.listener(hikari.StartedEvent)
async def on_start(event: hikari.StartedEvent) -> None:
await update_leaderboard()

def getLeaderboard() -> list:
return leaderboardEco

Expand Down
13 changes: 7 additions & 6 deletions src/extensions/general/customize.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self, inventory: Inventory, profile: Card, newPreset: list) -> None
self.newPreset = newPreset

@miru.button(label='Save', emoji='🖨️', style=hikari.ButtonStyle.SUCCESS, row=1)
async def save(self, button: miru.Button, ctx: miru.ViewContext):
async def save(self, ctx: miru.ViewContext, button: miru.Button):
self.cursor.execute('UPDATE profile SET active = 0 WHERE user_id = ?', (ctx.user.id,))
for item in self.newPreset:
name, type = str(item).split('-')
Expand All @@ -36,12 +36,12 @@ async def save(self, button: miru.Button, ctx: miru.ViewContext):
self.stop()

@miru.button(label='Cancel', emoji='✖️', style=hikari.ButtonStyle.DANGER, row=1)
async def cancel(self, button: miru.Button, ctx: miru.ViewContext):
async def cancel(self, ctx: miru.ViewContext, button: miru.Button):
await ctx.edit_response(components=[])
self.stop()

@miru.button(label='Preview', emoji='🔍', style=hikari.ButtonStyle.PRIMARY, row=1)
async def preview(self, button: miru.Button, ctx: miru.ViewContext):
async def preview(self, ctx: miru.ViewContext, button: miru.Button):
bg = Image.open(f'assets/img/general/profile/banner/{self.newPreset[0]}.png').convert('RGBA')
card = Image.open(f'assets/img/general/profile/base/{self.newPreset[1]}.png').convert('RGBA')
nametag = Image.open(f'assets/img/general/profile/nametag/{self.newPreset[2]}.png').convert('RGBA')
Expand All @@ -61,7 +61,7 @@ async def view_check(self, ctx: ViewContext) -> bool:
@lightbulb.implements(lightbulb.SlashCommand)
async def customize(ctx: lightbulb.Context, banner: str, base: str, nametag: str) -> None:
inventory = Inventory(ctx.member)
profile = Card(ctx.member)
profile = Card(ctx.member, ctx)

oldPreset = inventory.get_active_customs()
activePreset = [banner, base, nametag]
Expand All @@ -86,8 +86,9 @@ async def customize(ctx: lightbulb.Context, banner: str, base: str, nametag: str
.set_footer(text='This action cannot be undone.')
)

message = await ctx.respond(embed, components=view.build(), flags=hikari.MessageFlag.EPHEMERAL)
await view.start(message)
await ctx.respond(embed, components=view.build(), flags=hikari.MessageFlag.EPHEMERAL)
client = ctx.bot.d.get('client')
client.start_view(view)

@customize.autocomplete('banner', 'base', 'nametag')
async def search_autocomplete(opt: hikari.AutocompleteInteractionOption, ctx: hikari.AutocompleteInteraction):
Expand Down
Loading

0 comments on commit 280921f

Please sign in to comment.