├── LICENSE ├── README.md ├── command-list.md └── src ├── database ├── __init__.py └── database.json ├── game_libs ├── blackjack │ └── __init__.py └── roulette │ └── __init__.py └── main.py /LICENSE: -------------------------------------------------------------------------------- 1 | Modified MIT License (see Section 2) 2 | 3 | Copyright (c) 2021 Kendrik 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | 1. The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | 2. If you publish this software or a modified version of it, you must: 16 | a) Provide a visible link to the original repository link. 17 | GitHub's "forked from" label is sufficient. 18 | Original Repository: https://github.com/NoNameSpecified/UnbelievaBoat-Python-Bot 19 | b) Include a general statement that the software has been modified, if applicable. 20 | Github's "x commits ahead/behind" indicator is sufficient. 21 | 22 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 26 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 27 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 28 | SOFTWARE. 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # **UnbelievaBoat-like Discord Bot in python** 2 | ### For questions about the bot and how to set it up: ask me on Discord at ** 3 | 4 | 5 | ## update on release date: 6 | I decided to combine the SQLite switch with a complete frontend rework. 7 | Thus, it may take a little more time before the new code is released. I would like to release during next week (2nd june - 8th june) 8 | See the message for the released tag "Legacy JSON version" for more info. 9 | 10 | 11 | ## Official repo: 12 | https://github.com/NoNameSpecified/UnbelievaBoat-Python-Bot 13 | You're free to do anything with the code, I'd appreciate it if you would keep a link to the official repo tho :) 14 | 15 | 16 | ### - Info 17 | The Bot uses most of UnbelievaBoat's commands for minigames and economy (not moderation tho). 18 | With time, I have added quite some modifications, couldn't really say which tho, since I dont even use UB anymore lol. 19 | 20 | ### Please read `command_list.txt`. 21 | It not only helps users with how/what commands to use, it also gives tips for admins (using get-salary vs update-income for example). 22 | 23 | ### - Install & Use 24 | 1. Create a Discord Application for your bot (see https://youtu.be/b61kcgfOm_4, https://discord.com/developers/applications) 25 | 2. In the Discord Dev Portal, in the "Bot" tab of your application, **enable presence intent, server members intent, message content intent**. 26 | 3. Download the code, structured as in this repo. 27 | 4. Open the `main.py` file, line 40 and change the **token** to the one of your created bot. 28 | 5. Invite the bot to your server as shown in https://youtu.be/b61kcgfOm_4 29 | 6. Install python3 if you dont have it 30 | 7. Install the Discord Api for python3 using pip (`pip install discord.py`) 31 | 8. In your server, create a role named "botmaster" and give it to people who should be bot admins. 32 | 9. Launch main.py with **python3**. Beware !! On Windows, please use powershell, else path might not be recognized. 33 | 10. [optional]: by default, the currency emoji is set to 💰. 34 | You can change it as follows: changing line 75-77 in database/__init__.py. Note: if you uncomment 75, you gotta comment out line 77 ! (by putting a <#> before it, like in line 76. Then use change-currency-symbol (see src/commands.txt) or change "symbol_emoji" `in database/database.json`(needs to be a custom emoji). Contact me if you got issues. 35 | 36 | You should be good to go! 37 | 38 | 39 | ### - Goal 40 | It emerged from the problem of UB having a balance ceiling and no automated role-income increasing to user's balances. Obviously it's way bigger now. 41 | The goal was to make an easily customizable Template of a discord bot, also fixing the issues stated above. 42 | Another goal is to have the bot written in python so that it's easy to edit for every user. You can adjust the code so it fits exactly what you need. 43 | 44 | ### images 45 | On 09.02.24 update I added the option add images for items, that would be shown when calling the single item catalog info ("catalog item_name"). 46 | These images are loaded by URL - so they can be anything. I don't encourage however nor do I care if you use licensed images, since i have no way of checking that. 47 | But I definitely don't take any warranty as to what happens if you do use licensed images. Stay safe ! 48 | -------------------------------------------------------------------------------- /command-list.md: -------------------------------------------------------------------------------- 1 | # 📜 Command List for Skender Bot v2.0 2 | 3 | **Last updated:** 10.06.2025 (European date format) 4 | **Official Repository:** [github.com/NoNameSpecified/UnbelievaBoat-Python-Bot](https://github.com/NoNameSpecified/UnbelievaBoat-Python-Bot) 5 | 👉 For setup instructions, see `README.md`, for version info, see `version-info.md` 6 | 7 | > Prefix used here: `+` 8 | > You can change it in `main.py`. 9 | > 10 | > `` means required parameter, `[this]` means optional parameter 11 | 12 | --- 13 | 14 | ## 0. ℹ️ Information 15 | 16 | - Help page: `+help` 17 | 18 | --- 19 | 20 | ## 1. 🎲 Mini-Games 21 | 22 | - Blackjack: `+blackjack ` 23 | - Roulette: `+roulette ` 24 | 25 | --- 26 | 27 | ## 2. 💰 Balance & Money 28 | 29 | - Economy Stats: `+stats` 30 | - Check Balance: `+balance` 31 | - Deposit Money: `+deposit ` 32 | - Withdraw Money: `+withdraw ` 33 | - Give Money: `+give <@member> ` 34 | - Server Leaderboard: `+leaderboard [page] [-cash | -bank | -total]` 35 | 36 | ### 2.1 Admin Commands – Balance & Money 37 | 38 | - `+add-money <@member> ` 39 | - `+remove-money <@member> [cash/bank]` 40 | ℹ️ Default: bank 41 | - `+add-money-role <@role> ` 42 | - `+remove-money-role <@role> ` 43 | ℹ️ Removes from bank. If amount > user balance, it sets balance to 0. 44 | - `+clear-db` 45 | ℹ️ Removes users who left the server from the database (irreversibly). 46 | 47 | --- 48 | 49 | ## 3. 💼 Income Commands 50 | 51 | - `+slut` 52 | - `+crime` 53 | - `+work` 54 | - `+rob` 55 | 56 | --- 57 | 58 | ## 4. 🛠️ Customization (Admin only) 59 | 60 | - `+module-info [module]` 61 | Get module (income commands) info. You can use this info to later edit the values. 62 | If you don't know the module names, just use +module without any parameter. 63 | - `+change-variable ` 64 | Change variable settings 65 | Tip: Use `+module` first and then use change-variable. 66 | - `+change-action ` 67 | Example: change delay (cooldown) for blackjack. 68 | - `+change-currency ` 69 | Only emojis uploaded to your server are valid, not a discord wide one. 70 | - `+set-income-reset ` 71 | Controls whether income accumulates or if you always only get one-day-income. 72 | By default, it is set to true. 73 | - `+set-passive-chat-income ` 74 | Passive chat income means that the user receives a certain sum for being active and sending messages. 75 | The cooldown for this is the same as for gaining xp per message. 76 | 77 | --- 78 | 79 | ## 5. 🎁 Items 80 | 81 | - `+buy-item ` 82 | - `+give-item <@member> ` 83 | - `+inventory [page]` – See your own inventory 84 | - `+user-inventory <@member> [page]` – See another user's inventory 85 | - `+use ` 86 | - `+catalog [item_name]` 87 | Just +catalog shows a list of all items available. 88 | +catalog name shows detailed information of a specific item. 89 | 90 | ### 5.1 Admin Commands – Items 91 | 92 | - `+create-item` 93 | - `+delete-item ` 94 | ℹ️ Completely removes item for everyone 95 | - `+remove-user-item <@member> ` 96 | - `+spawn-item <@member> [amount]` 97 | ℹ️ Adds an (already created) item to inventory 98 | 99 | --- 100 | 101 | ## 6. 👥 Income Roles 102 | 103 | Users with a specific role will receive daily income (e.g., 100 = 100/day) 104 | 105 | - `+list-roles` 106 | - `+collect` 107 | Uses `income_reset` setting to determine payout behavior. 108 | Can/should be disabled depending on if you want to use update-income 109 | 110 | ### 6.1 Admin Commands – Income Roles 111 | 112 | - `+add-income-role <@role> ` 113 | - `+remove-income-role <@role>` 114 | - `+update-income-role <@role> ` 115 | - `+update-income` 116 | Pays all users with income roles. 117 | ⚠️ Also affected by `income_reset`. 118 | 119 | 💡 **Tip:** 120 | Use `+collect` with `income_reset` set to true (default) and avoid using `update-income`. 121 | To disable `+collect`, edit `bot.py` and comment out the relevant block (elif command in ["collect" ...). 122 | 123 | --- 124 | 125 | ## 7. 🧬 Levels 126 | 127 | - `+level [@member]` – View own or mentioned user’s level 128 | - `+all-levels` – Overview of all levels & rewards 129 | - `+level-lb [page]` – Level leaderboard 130 | 131 | ### 7.1 Admin Commands – Levels 132 | 133 | - `+change-levels` – Modify levels and their thresholds, rewards (money, roles to give or remove, items), and XP channels 134 | - `+add-xp <@member> ` 135 | - `+remove-xp <@member> ` 136 | 137 | ℹ️ To modify passive chat income, use `+set-passive-chat-income` 138 | 139 | --- 140 | -------------------------------------------------------------------------------- /src/database/__init__.py: -------------------------------------------------------------------------------- 1 | import json, os, time, random, math, sys, discord, math, asyncio 2 | from datetime import datetime 3 | from datetime import timedelta 4 | import calendar 5 | 6 | # custom blackjack game thing 7 | from game_libs.blackjack import blackjack_discord_implementation 8 | # custom roulette game thing 9 | from game_libs.roulette import roulette_discord_implementation 10 | 11 | """ 12 | 13 | the database handler of the unbelievaboat-python discord bot 14 | // is imported by ../main.py 15 | 16 | """ 17 | 18 | 19 | class pythonboat_database_handler: 20 | # always called when imported in main.py 21 | def __init__(self, client): 22 | # we do the path from the main.py file, so we go into the db folder, then select 23 | self.pathToJson = "database/database.json" 24 | self.client = client 25 | # for the json "variables", dont want to make a whole function to find index for variables 26 | # wont be many anyways. so making it manually 27 | self.variable_dict = { 28 | "slut": 0, 29 | "crime": 1, 30 | "work": 2, 31 | "rob": 3 32 | } 33 | 34 | # for colors 35 | self.discord_error_rgb_code = discord.Color.from_rgb(239, 83, 80) 36 | self.discord_blue_rgb_code = discord.Color.from_rgb(3, 169, 244) 37 | self.discord_success_rgb_code = discord.Color.from_rgb(102, 187, 106) 38 | 39 | # check if file is created, else create it 40 | if not os.path.exists(self.pathToJson): 41 | creating_file = open(self.pathToJson, "w") 42 | # adding default json config into the file if creating new 43 | # all the users will get created automatically in the function self.find_index_in_db() 44 | # but for the different jobs etc the program needs configs for variables and symbols 45 | creating_file.write("""{\n\t"userdata": [], 46 | "variables":[ 47 | {"name":"slut","delay":15,"min_revenue":50,"max_revenue":400,"proba":50,"win_phrases":["You made","Your dad likes it so much he gives you"],"lose_phrases":["You were fined","Your uncle didn't like the encounter. You pay"],"min_lose_amount_percentage":2,"max_lose_amount_percentage":5}, 48 | {"name":"crime","delay":60,"min_revenue":100,"max_revenue":1200,"proba":30,"win_phrases":["You commited a crime and got","You robbed a bank and got"],"lose_phrases":["You were fined","MacGyver finds you, you pay"],"min_lose_amount_percentage":10,"max_lose_amount_percentage":20}, 49 | {"name":"work","delay":10,"min_revenue":50,"max_revenue":200,"win_phrases":["You worked at SubWay and made","You helped someone do his homework and got"]}, 50 | {"name":"rob","delay":45,"proba":50,"min_gain_amount_percentage":10,"max_gain_amount_percentage":20,"min_lose_amount_percentage":10,"max_lose_amount_percentage":20,"win_phrases":["You robbed and got"],"lose_phrases":["You were caught robbing and have to pay"]}], 51 | "symbols": [ 52 | {"name":"currency_symbol","symbol_emoji":":dollar:"} 53 | ], 54 | "items": [ 55 | {} 56 | ], 57 | "income_roles": [ 58 | {} 59 | ] 60 | \n}""") 61 | creating_file.close() 62 | 63 | # 64 | 65 | # check if json file is corrupted 66 | # -> in self.check_json() 67 | # called from main.py 68 | 69 | def get_currency_symbol(self, test=False, value="unset"): 70 | if not test: 71 | # get currency symbol to use 72 | temp_json_opening = open(self.pathToJson, "r") 73 | temp_json_content = json.load(temp_json_opening) 74 | # the currency symbol is always at position 0 in the "symbols" part 75 | currency_symbol = temp_json_content["symbols"][0]["symbol_emoji"] 76 | #self.currency_symbol = discord.utils.get(self.client.emojis, name=currency_symbol) 77 | # perhaps currency symbol is too difficult for regular admins to handle, so ill disable it as default. 78 | self.currency_symbol = "💰" 79 | else: 80 | try: 81 | self.currency_symbol = discord.utils.get(self.client.emojis, name=value) 82 | print(str(self.currency_symbol)) 83 | if self.currency_symbol == None: 84 | return "error" 85 | except: 86 | return "error" 87 | 88 | # if we handle a already created file, we need certain variables 89 | async def check_json(self): 90 | temp_json_opening = open(self.pathToJson, "r") 91 | temp_json_content = json.load(temp_json_opening) 92 | """ 93 | possibly to add : 94 | improve the error system, raising specific errors with a "error_info" 95 | for example : "userdata missing", or "slut missing", or even "slut min_revenue missing" 96 | """ 97 | try: 98 | check_content = temp_json_content 99 | # userdata space 100 | userdata = check_content["userdata"] 101 | # variables 102 | variables = check_content["variables"] 103 | slut = variables[self.variable_dict["slut"]] 104 | crime = variables[self.variable_dict["crime"]] 105 | work = variables[self.variable_dict["work"]] 106 | rob = variables[self.variable_dict["rob"]] 107 | # symbol 108 | currency_symbol = check_content["symbols"][0] 109 | items = check_content["items"] 110 | roles = check_content["income_roles"] 111 | 112 | # didnt fail, so we're good 113 | temp_json_opening.close() 114 | except Exception as e: 115 | # something is missing, inform client 116 | return "error" 117 | 118 | """ 119 | GLOBAL FUNCTIONS 120 | """ 121 | 122 | # need to overwrite the whole json when updating, luckily the database won't be enormous 123 | def overwrite_json(self, content): 124 | self.json_db = open(self.pathToJson, "w") 125 | self.clean_json = json.dumps(content, indent=4, separators=(",", ": ")) 126 | self.json_db.write(self.clean_json) 127 | self.json_db.close() 128 | 129 | # find the user in the database 130 | def find_index_in_db(self, data_to_search, user_to_find, fail_safe=False): 131 | user_to_find = int(user_to_find) 132 | for i in range(len(data_to_search)): 133 | if data_to_search[i]["user_id"] == user_to_find: 134 | # print("\nfound user\n") 135 | return int(i), "none" 136 | 137 | # in this case, this isnt a user which isnt yet registrated 138 | # but someone who doesnt exist on the server 139 | # or at least thats what is expected when calling with this parameter 140 | if fail_safe: 141 | return 0, "error" 142 | 143 | print("\ncreating user\n") 144 | # we did NOT find him, which means he doesn't exist yet 145 | # so we automatically create him 146 | # edit on 13.02.24: this is fucking useless WTF 147 | data_to_search.append({ 148 | "user_id": user_to_find, 149 | "cash": 0, 150 | "bank": 0, 151 | # "balance" : cash + bank 152 | # "roles": "None" ; will be checked when calculating weekly auto-role-income 153 | "items": "none", 154 | "used_items": "none", 155 | "last_slut": "none", 156 | "last_work": "none", 157 | "last_crime": "none", 158 | "last_rob": "none" 159 | }) 160 | 161 | """ 162 | POSSIBLE ISSUE : 163 | that we need to create user by overwrite, then problem of doing that while another command is 164 | supposed to have it open etc. hopefully it works just as such 165 | """ 166 | # now that the user is created, re-check and return int 167 | 168 | for i in range(len(data_to_search)): 169 | if data_to_search[i]["user_id"] == user_to_find: 170 | return int(i), data_to_search 171 | 172 | """ 173 | CLIENT-DB HANDLING 174 | """ 175 | 176 | async def blackjack(self, user, bet, bot, channel, username, user_pfp, message): 177 | # load json 178 | json_file = open(self.pathToJson, "r") 179 | json_content = json.load(json_file) 180 | user_index, new_data = self.find_index_in_db(json_content["userdata"], user) 181 | 182 | if new_data != "none": 183 | json_content["userdata"] = new_data 184 | 185 | json_user_content = json_content["userdata"][user_index] 186 | 187 | # get user stuff 188 | user_cash = json_user_content["cash"] 189 | 190 | if bet == "all": 191 | bet = user_cash 192 | if bet < 100: 193 | return "error", f"❌ Not at least 100 in cash. You currently have {str(self.currency_symbol)} {'{:,}'.format(user_cash)} on hand." 194 | else: 195 | bet = int(bet) 196 | 197 | if bet > user_cash: 198 | return "error", f"❌ You don't have that much money in cash. You currently have {str(self.currency_symbol)} {'{:,}'.format(user_cash)} on hand." 199 | 200 | # the actual game 201 | # start it 202 | startInstance = blackjack_discord_implementation(bot, channel, self.currency_symbol) 203 | bjPlay = await startInstance.play(bot, channel, username, user_pfp, message, bet) 204 | 205 | if bjPlay == "win": 206 | json_user_content["cash"] += bet 207 | elif bjPlay == "blackjack": 208 | json_user_content["cash"] += bet * 1.5 209 | elif bjPlay == "loss": 210 | json_user_content["cash"] -= bet 211 | elif bjPlay == "bust": 212 | pass 213 | else: 214 | return "error", "❌ error unknown, contact admin" 215 | 216 | # overwrite, end 217 | json_content["userdata"][user_index] = json_user_content 218 | self.overwrite_json(json_content) 219 | 220 | return "success", "success" 221 | 222 | # 223 | # ROULETTE 224 | # 225 | 226 | async def roulette(self, user, bet, space, bot, channel, username, user_pfp, mention): 227 | # load json 228 | json_file = open(self.pathToJson, "r") 229 | json_content = json.load(json_file) 230 | user_index, new_data = self.find_index_in_db(json_content["userdata"], user) 231 | 232 | if new_data != "none": 233 | json_content["userdata"] = new_data 234 | 235 | json_user_content = json_content["userdata"][user_index] 236 | 237 | # get user stuff 238 | user_cash = json_user_content["cash"] 239 | 240 | if bet == "all": 241 | bet = user_cash 242 | if bet < 100: 243 | return "error", f"❌ Not at least 100 in cash. You currently have {str(self.currency_symbol)} {'{:,}'.format(user_cash)} on hand." 244 | else: 245 | bet = int(bet) 246 | 247 | if bet > user_cash: 248 | return "error", f"❌ You don't have that much money in cash. You currently have {str(self.currency_symbol)} {'{:,}'.format(user_cash)} on hand." 249 | 250 | # the actual game 251 | # start it 252 | startInstance = roulette_discord_implementation(bot, channel, self.currency_symbol) 253 | roulettePlay, multiplicator = await startInstance.play(bot, channel, username, user_pfp, bet, space, mention) 254 | # print("done with roulette call") 255 | # roulettePlay will be 1 for won, 0 for lost 256 | if roulettePlay: 257 | json_user_content["cash"] += (bet * multiplicator) - bet 258 | elif roulettePlay == 0: 259 | json_user_content["cash"] -= bet 260 | else: 261 | return "error", "❌ error unknown, contact admin" 262 | 263 | # overwrite, end 264 | json_content["userdata"][user_index] = json_user_content 265 | self.overwrite_json(json_content) 266 | # print("FINISHED writing") 267 | return "success", "success" 268 | 269 | # 270 | # SLUT 271 | # 272 | 273 | async def slut(self, user, channel, username, user_pfp): 274 | # load json 275 | json_file = open(self.pathToJson, "r") 276 | json_content = json.load(json_file) 277 | user_index, new_data = self.find_index_in_db(json_content["userdata"], user) 278 | 279 | if new_data != "none": 280 | json_content["userdata"] = new_data 281 | 282 | json_user_content = json_content["userdata"][user_index] 283 | 284 | """ 285 | SPECIFIC TIME ETC 286 | """ 287 | # grep values 288 | slut_data = json_content["variables"][self.variable_dict["slut"]] 289 | 290 | # delay will ALWAYS be in MINUTES 291 | delay = slut_data["delay"] 292 | proba = slut_data["proba"] 293 | 294 | time_check = False 295 | now = datetime.now() 296 | if json_user_content["last_slut"] == "none": 297 | # never done it, so go ahead 298 | time_check = True 299 | # else, gotta check if enough time passed since last slut 300 | else: 301 | last_slut_string = json_user_content["last_slut"] 302 | # get a timeobject from the string 303 | last_slut = datetime.strptime(last_slut_string, '%Y-%m-%d %H:%M:%S.%f') 304 | # calculate difference, see if it works 305 | passed_time = now - last_slut 306 | passed_time_minutes = passed_time.total_seconds() // 60.0 307 | if passed_time_minutes == 0: 308 | # because of // division it might display 0 309 | passed_time_minutes = 1 310 | if passed_time_minutes > delay: 311 | time_check = True 312 | else: 313 | time_check = False 314 | delay_remaining = delay - passed_time_minutes 315 | # moving the block here for cleaner code 316 | if time_check == False: 317 | color = self.discord_blue_rgb_code 318 | embed = discord.Embed(description=f"⏱ ️You cannot be a slut for {math.ceil(delay_remaining)} minutes.", 319 | color=color) 320 | embed.set_author(name=username, icon_url=user_pfp) 321 | await channel.send(embed=embed) 322 | return "success", "success" 323 | # else: 324 | # he can do it 325 | 326 | """ 327 | ACTUAL FUNCTION 328 | """ 329 | # so, explanation : 330 | # not actually using probabilites or so, just a random number between 1 and 2 331 | # and if for example probability is 50%, then the random num should be > 1.5 in order to win 332 | slut_success = random.randint(0, 100) 333 | 334 | if proba < slut_success: 335 | # LOST 336 | 337 | lose_phrases = random.choice(slut_data["lose_phrases"]) 338 | lose_percentage = random.randint(slut_data["min_lose_amount_percentage"], 339 | slut_data["max_lose_amount_percentage"]) 340 | balance = json_user_content["cash"] + json_user_content["bank"] 341 | loss = balance * (lose_percentage / 100) 342 | # round up, no floats 343 | loss = round(loss, 0) 344 | color = self.discord_error_rgb_code 345 | embed = discord.Embed( 346 | description=f"{lose_phrases} {str(self.currency_symbol)} **{'{:,}'.format(int(loss))}**", color=color) 347 | embed.set_author(name=username, icon_url=user_pfp) 348 | embed.set_footer(text="r.i.p") 349 | await channel.send(embed=embed) 350 | json_user_content["cash"] -= loss 351 | # update last slut time 352 | json_user_content["last_slut"] = str(now) 353 | # overwrite, end 354 | json_content["userdata"][user_index] = json_user_content 355 | self.overwrite_json(json_content) 356 | 357 | return "success", "success" 358 | 359 | else: 360 | # SUCCESS 361 | win_phrases = random.choice(slut_data["win_phrases"]) 362 | gain = random.randint(slut_data["min_revenue"], slut_data["max_revenue"]) 363 | # round up, no floats 364 | gain = round(gain, 0) 365 | color = self.discord_success_rgb_code 366 | embed = discord.Embed( 367 | description=f"{win_phrases} {str(self.currency_symbol)} **{'{:,}'.format(int(gain))}**", color=color) 368 | embed.set_author(name=username, icon_url=user_pfp) 369 | embed.set_footer(text="gg") 370 | await channel.send(embed=embed) 371 | json_user_content["cash"] += gain 372 | # update last slut time 373 | json_user_content["last_slut"] = str(now) 374 | # overwrite, end 375 | json_content["userdata"][user_index] = json_user_content 376 | self.overwrite_json(json_content) 377 | 378 | return "success", "success" 379 | 380 | # we never reach this part of the code 381 | 382 | # 383 | # CRIME 384 | # 385 | 386 | async def crime(self, user, channel, username, user_pfp): 387 | # load json 388 | json_file = open(self.pathToJson, "r") 389 | json_content = json.load(json_file) 390 | user_index, new_data = self.find_index_in_db(json_content["userdata"], user) 391 | 392 | if new_data != "none": 393 | json_content["userdata"] = new_data 394 | 395 | json_user_content = json_content["userdata"][user_index] 396 | 397 | """ 398 | SPECIFIC TIME ETC 399 | """ 400 | # grep values 401 | crime_data = json_content["variables"][self.variable_dict["crime"]] 402 | 403 | # delay will ALWAYS be in MINUTES 404 | delay = crime_data["delay"] 405 | proba = crime_data["proba"] 406 | 407 | time_check = False 408 | now = datetime.now() 409 | if json_user_content["last_crime"] == "none": 410 | # never done it, so go ahead 411 | time_check = True 412 | # else, gotta check if enough time passed since last slut 413 | else: 414 | last_slut_string = json_user_content["last_crime"] 415 | # get a timeobject from the string 416 | last_slut = datetime.strptime(last_slut_string, '%Y-%m-%d %H:%M:%S.%f') 417 | # calculate difference, see if it works 418 | passed_time = now - last_slut 419 | passed_time_minutes = passed_time.total_seconds() // 60.0 420 | if passed_time_minutes == 0: 421 | # because of // division it might display 0 422 | passed_time_minutes = 1 423 | if passed_time_minutes > delay: 424 | time_check = True 425 | else: 426 | time_check = False 427 | delay_remaining = delay - passed_time_minutes 428 | # moving the block here for cleaner code 429 | if time_check == False: 430 | color = self.discord_blue_rgb_code 431 | embed = discord.Embed(description=f"⏱ ️You cannot commit a crime for {math.ceil(delay_remaining)} minutes.", 432 | color=color) 433 | embed.set_author(name=username, icon_url=user_pfp) 434 | await channel.send(embed=embed) 435 | return "success", "success" 436 | # else: 437 | # print("he can do it") 438 | 439 | """ 440 | ACTUAL FUNCTION 441 | """ 442 | # so, explanation : 443 | # not actually using probabilites or so, just a random number between 1 and 2 444 | # and if for example probability is 50%, then the random num should be > 1.5 in order to win 445 | crime_success = random.randint(0, 100) 446 | 447 | if proba < crime_success: 448 | # LOST 449 | 450 | lose_phrases = random.choice(crime_data["lose_phrases"]) 451 | lose_percentage = random.randint(crime_data["min_lose_amount_percentage"], 452 | crime_data["max_lose_amount_percentage"]) 453 | balance = json_user_content["cash"] + json_user_content["bank"] 454 | loss = balance * (lose_percentage / 100) 455 | # round up, no floats 456 | loss = round(loss, 0) 457 | color = self.discord_error_rgb_code 458 | embed = discord.Embed( 459 | description=f"{lose_phrases} {str(self.currency_symbol)} **{'{:,}'.format(int(loss))}**", color=color) 460 | embed.set_author(name=username, icon_url=user_pfp) 461 | embed.set_footer(text="r.i.p") 462 | await channel.send(embed=embed) 463 | json_user_content["cash"] -= loss 464 | # update last slut time 465 | json_user_content["last_crime"] = str(now) 466 | # overwrite, end 467 | json_content["userdata"][user_index] = json_user_content 468 | self.overwrite_json(json_content) 469 | 470 | return "success", "success" 471 | 472 | else: 473 | # SUCCESS 474 | win_phrases = random.choice(crime_data["win_phrases"]) 475 | gain = random.randint(crime_data["min_revenue"], crime_data["max_revenue"]) 476 | # round up, no floats 477 | gain = round(gain, 0) 478 | color = self.discord_success_rgb_code 479 | embed = discord.Embed( 480 | description=f"{win_phrases} {str(self.currency_symbol)} **{'{:,}'.format(int(gain))}**", color=color) 481 | embed.set_author(name=username, icon_url=user_pfp) 482 | embed.set_footer(text="gg") 483 | await channel.send(embed=embed) 484 | json_user_content["cash"] += gain 485 | # update last slut time 486 | json_user_content["last_crime"] = str(now) 487 | # overwrite, end 488 | json_content["userdata"][user_index] = json_user_content 489 | self.overwrite_json(json_content) 490 | 491 | return "success", "success" 492 | 493 | # we never reach this part of the code 494 | 495 | # 496 | # WORK 497 | # 498 | 499 | async def work(self, user, channel, username, user_pfp): 500 | # load json 501 | json_file = open(self.pathToJson, "r") 502 | json_content = json.load(json_file) 503 | user_index, new_data = self.find_index_in_db(json_content["userdata"], user) 504 | 505 | if new_data != "none": 506 | json_content["userdata"] = new_data 507 | 508 | json_user_content = json_content["userdata"][user_index] 509 | 510 | """ 511 | SPECIFIC TIME ETC 512 | """ 513 | # grep values 514 | work_data = json_content["variables"][self.variable_dict["work"]] 515 | 516 | # delay will ALWAYS be in MINUTES 517 | delay = work_data["delay"] 518 | 519 | time_check = False 520 | now = datetime.now() 521 | if json_user_content["last_work"] == "none": 522 | # never done it, so go ahead 523 | time_check = True 524 | # else, gotta check if enough time passed since last slut 525 | else: 526 | last_slut_string = json_user_content["last_work"] 527 | # get a timeobject from the string 528 | last_slut = datetime.strptime(last_slut_string, '%Y-%m-%d %H:%M:%S.%f') 529 | # calculate difference, see if it works 530 | passed_time = now - last_slut 531 | passed_time_minutes = passed_time.total_seconds() // 60.0 532 | if passed_time_minutes == 0: 533 | # because of // division it might display 0 534 | passed_time_minutes = 1 535 | if passed_time_minutes > delay: 536 | time_check = True 537 | else: 538 | time_check = False 539 | delay_remaining = delay - passed_time_minutes 540 | # moving the block here for cleaner code 541 | if time_check == False: 542 | color = self.discord_blue_rgb_code 543 | embed = discord.Embed(description=f"⏱ ️You cannot work for {math.ceil(delay_remaining)} minutes.", 544 | color=color) 545 | embed.set_author(name=username, icon_url=user_pfp) 546 | await channel.send(embed=embed) 547 | return "success", "success" 548 | # else: 549 | # print("he can do it") 550 | 551 | """ 552 | ACTUAL FUNCTION 553 | """ 554 | 555 | # work is always a success 556 | win_phrases = random.choice(work_data["win_phrases"]) 557 | gain = random.randint(work_data["min_revenue"], work_data["max_revenue"]) 558 | # round up, no floats 559 | gain = round(gain, 0) 560 | color = self.discord_success_rgb_code 561 | embed = discord.Embed(description=f"{win_phrases} {str(self.currency_symbol)} **{'{:,}'.format(int(gain))}**", 562 | color=color) 563 | embed.set_author(name=username, icon_url=user_pfp) 564 | embed.set_footer(text="capitalism is great") 565 | await channel.send(embed=embed) 566 | json_user_content["cash"] += gain 567 | # update last slut time 568 | json_user_content["last_work"] = str(now) 569 | # overwrite, end 570 | json_content["userdata"][user_index] = json_user_content 571 | self.overwrite_json(json_content) 572 | 573 | return "success", "success" 574 | 575 | # 576 | # ROB 577 | # 578 | 579 | async def rob(self, user, channel, username, user_pfp, user_to_rob): 580 | # load json 581 | json_file = open(self.pathToJson, "r") 582 | json_content = json.load(json_file) 583 | user_index, new_data = self.find_index_in_db(json_content["userdata"], user) 584 | 585 | if new_data != "none": 586 | json_content["userdata"] = new_data 587 | 588 | json_user_content = json_content["userdata"][user_index] 589 | 590 | """ 591 | SPECIFIC TIME ETC 592 | """ 593 | # grep values 594 | rob_data = json_content["variables"][self.variable_dict["rob"]] 595 | 596 | # delay will ALWAYS be in MINUTES 597 | delay = rob_data["delay"] 598 | proba = rob_data["proba"] 599 | 600 | time_check = False 601 | now = datetime.now() 602 | if json_user_content["last_rob"] == "none": 603 | # never done it, so go ahead 604 | time_check = True 605 | # else, gotta check if enough time passed since last slut 606 | else: 607 | last_slut_string = json_user_content["last_rob"] 608 | # get a timeobject from the string 609 | last_slut = datetime.strptime(last_slut_string, '%Y-%m-%d %H:%M:%S.%f') 610 | # calculate difference, see if it works 611 | passed_time = now - last_slut 612 | passed_time_minutes = passed_time.total_seconds() // 60.0 613 | if passed_time_minutes == 0: 614 | # because of // division it might display 0 615 | passed_time_minutes = 1 616 | if passed_time_minutes > delay: 617 | time_check = True 618 | else: 619 | time_check = False 620 | delay_remaining = delay - passed_time_minutes 621 | # moving the block here for cleaner code 622 | if time_check == False: 623 | color = self.discord_blue_rgb_code 624 | embed = discord.Embed(description=f"⏱ ️You cannot rob someone for {math.ceil(delay_remaining)} minutes.", 625 | color=color) 626 | embed.set_author(name=username, icon_url=user_pfp) 627 | await channel.send(embed=embed) 628 | return "success", "success" 629 | # else: 630 | # print("he can do it") 631 | 632 | """ 633 | ACTUAL FUNCTION 634 | """ 635 | 636 | # check if user you want to rob exists 637 | robbed_user, status = self.find_index_in_db(json_content["userdata"], user_to_rob, fail_safe=True) 638 | if (robbed_user == 0 and status == "error"): 639 | # we didnt find him 640 | color = self.discord_error_rgb_code 641 | embed = discord.Embed(description=f"❌ Invalid `` argument given.\n\nUsage:\n`rob `", 642 | color=color) 643 | embed.set_author(name=username, icon_url=user_pfp) 644 | await channel.send(embed=embed) 645 | return "success", "success" 646 | 647 | if str(user).strip() == str(user_to_rob).strip(): 648 | # you cannot rob yourself 649 | color = self.discord_error_rgb_code 650 | embed = discord.Embed(description=f"❌ You cannot rob yourself!", color=color) 651 | embed.set_author(name=username, icon_url=user_pfp) 652 | await channel.send(embed=embed) 653 | return "success", "success" 654 | 655 | # you cannot rob from people who have less money than you 656 | robbed_user_data = json_content["userdata"][robbed_user] 657 | robbed_balance = robbed_user_data["cash"] + robbed_user_data["bank"] 658 | user_balance = json_user_content["cash"] + json_user_content["bank"] 659 | if robbed_balance < user_balance: 660 | lose_percentage = random.randint(rob_data["min_lose_amount_percentage"], 661 | rob_data["max_lose_amount_percentage"]) 662 | balance = json_user_content["cash"] + json_user_content["bank"] 663 | loss = balance * (lose_percentage / 100) 664 | # round up, no floats 665 | loss = round(loss, 0) 666 | 667 | color = self.discord_error_rgb_code 668 | embed = discord.Embed( 669 | description=f"❌ You've been fined {str(self.currency_symbol)} **{'{:,}'.format(int(loss))}** for trying to rob a person more poor than you.", 670 | color=color) 671 | embed.set_author(name=username, icon_url=user_pfp) 672 | await channel.send(embed=embed) 673 | 674 | return "success", "success" 675 | 676 | # 677 | # Normal robbing now 678 | # 679 | 680 | # so, explanation : 681 | # not actually using probabilites or so, just a random number between 1 and 2 682 | # and if for example probability is 50%, then the random num should be > 1.5 in order to win 683 | crime_success = random.randint(0, 100) 684 | 685 | if proba < crime_success: 686 | # LOST 687 | 688 | lose_phrases = random.choice(rob_data["lose_phrases"]) 689 | lose_percentage = random.randint(rob_data["min_lose_amount_percentage"], 690 | rob_data["max_lose_amount_percentage"]) 691 | balance = json_user_content["cash"] + json_user_content["bank"] 692 | loss = balance * (lose_percentage / 100) 693 | # round up, no floats 694 | loss = round(loss, 0) 695 | color = self.discord_error_rgb_code 696 | embed = discord.Embed( 697 | description=f"❌ {lose_phrases} {str(self.currency_symbol)} **{'{:,}'.format(int(loss))}**", color=color) 698 | embed.set_author(name=username, icon_url=user_pfp) 699 | embed.set_footer(text="robbing isn't cool") 700 | await channel.send(embed=embed) 701 | json_user_content["cash"] -= loss 702 | # update last slut time 703 | json_user_content["last_rob"] = str(now) 704 | # overwrite, end 705 | json_content["userdata"][user_index] = json_user_content 706 | self.overwrite_json(json_content) 707 | 708 | return "success", "success" 709 | 710 | else: 711 | # SUCCESS 712 | 713 | win_phrases = random.choice(rob_data["win_phrases"]) 714 | gain_percentage = random.randint(rob_data["min_gain_amount_percentage"], 715 | rob_data["max_gain_amount_percentage"]) 716 | 717 | robbed_cash = robbed_user_data["cash"] 718 | gain = robbed_cash * (gain_percentage / 100) 719 | 720 | # round up, no floats 721 | gain = round(gain, 0) 722 | color = self.discord_success_rgb_code 723 | embed = discord.Embed( 724 | description=f"✅ {win_phrases} {str(self.currency_symbol)} **{'{:,}'.format(int(gain))}**", color=color) 725 | embed.set_author(name=username, icon_url=user_pfp) 726 | embed.set_footer(text="lucky") 727 | await channel.send(embed=embed) 728 | json_user_content["cash"] += gain 729 | # update last slut time 730 | json_user_content["last_rob"] = str(now) 731 | # overwrite, end 732 | json_content["userdata"][user_index] = json_user_content 733 | self.overwrite_json(json_content) 734 | 735 | return "success", "success" 736 | 737 | # this code is never reached 738 | 739 | # 740 | # BALANCE 741 | # 742 | 743 | async def balance(self, user, channel, userbal_to_check, username_to_check, userpfp_to_check, not_done): 744 | # load json 745 | # print(not_done) 746 | if not_done: await asyncio.sleep(1) 747 | json_file = open(self.pathToJson, "r") 748 | # print("opened json") 749 | json_content = json.load(json_file) 750 | user_index, new_data = self.find_index_in_db(json_content["userdata"], user) 751 | # check if user exists 752 | # no need for fail_safe option because that is already checked in main.py before calling this function 753 | checked_user, status = self.find_index_in_db(json_content["userdata"], userbal_to_check) 754 | 755 | if new_data != "none": 756 | json_content["userdata"] = new_data 757 | 758 | json_user_content = json_content["userdata"][checked_user] 759 | check_cash = "{:,}".format(int(json_user_content["cash"])) 760 | check_bank = "{:,}".format(int(json_user_content["bank"])) 761 | check_bal = "{:,}".format(int(json_user_content["cash"] + json_user_content["bank"])) 762 | minute_formatted = f"0{datetime.now().minute}" if datetime.now().minute < 10 else datetime.now().minute 763 | formatted_time = str(f"{datetime.now().hour}:{minute_formatted}") 764 | 765 | color = self.discord_blue_rgb_code 766 | embed = discord.Embed(color=color) 767 | embed.add_field(name="**Cash**", value=f"{str(self.currency_symbol)} {check_cash}", inline=True) 768 | embed.add_field(name="**Bank**", value=f"{str(self.currency_symbol)} {check_bank}", inline=True) 769 | embed.add_field(name="**Net Worth:**", value=f"{str(self.currency_symbol)} {check_bal}", inline=True) 770 | embed.set_author(name=username_to_check, icon_url=userpfp_to_check) 771 | embed.set_footer(text=f"today at {formatted_time}") 772 | await channel.send(embed=embed) 773 | 774 | self.overwrite_json(json_content) 775 | return 776 | 777 | # 778 | # DEPOSIT 779 | # 780 | 781 | async def deposit(self, user, channel, username, user_pfp, amount): 782 | # load json 783 | json_file = open(self.pathToJson, "r") 784 | json_content = json.load(json_file) 785 | user_index, new_data = self.find_index_in_db(json_content["userdata"], user) 786 | 787 | if new_data != "none": 788 | json_content["userdata"] = new_data 789 | 790 | json_user_content = json_content["userdata"][user_index] 791 | 792 | user_cash = json_user_content["cash"] 793 | 794 | if amount == "all": 795 | amount = user_cash 796 | if amount < 0: 797 | return "error", "❌ No negative values." 798 | else: 799 | amount = int(amount) 800 | if amount > user_cash: 801 | return "error", f"❌ You don't have that much money to deposit. You currently have {str(self.currency_symbol)} {'{:,}'.format(user_cash)} on hand." 802 | 803 | json_user_content["cash"] -= amount 804 | json_user_content["bank"] += amount 805 | 806 | color = self.discord_success_rgb_code 807 | embed = discord.Embed( 808 | description=f"✅ Deposited {str(self.currency_symbol)} {'{:,}'.format(int(amount))} to your bank!", 809 | color=color) 810 | embed.set_author(name=username, icon_url=user_pfp) 811 | await channel.send(embed=embed) 812 | 813 | # overwrite, end 814 | json_content["userdata"][user_index] = json_user_content 815 | self.overwrite_json(json_content) 816 | 817 | return "success", "success" 818 | 819 | # 820 | # WITHDRAW 821 | # 822 | 823 | async def withdraw(self, user, channel, username, user_pfp, amount): 824 | # load json 825 | json_file = open(self.pathToJson, "r") 826 | json_content = json.load(json_file) 827 | user_index, new_data = self.find_index_in_db(json_content["userdata"], user) 828 | 829 | if new_data != "none": 830 | json_content["userdata"] = new_data 831 | 832 | json_user_content = json_content["userdata"][user_index] 833 | 834 | user_bank = json_user_content["bank"] 835 | 836 | if amount == "all": 837 | amount = user_bank 838 | if amount < 0: 839 | return "error", "❌ No negative values." 840 | else: 841 | amount = int(amount) 842 | if amount > user_bank: 843 | return "error", f"❌ You don't have that much money to withdraw. You currently have {str(self.currency_symbol)} {'{:,}'.format(user_bank)} in the bank." 844 | 845 | json_user_content["cash"] += amount 846 | json_user_content["bank"] -= amount 847 | 848 | color = self.discord_success_rgb_code 849 | embed = discord.Embed( 850 | description=f"✅ Withdrew {str(self.currency_symbol)} {'{:,}'.format(int(amount))} from your bank!", 851 | color=color) 852 | embed.set_author(name=username, icon_url=user_pfp) 853 | await channel.send(embed=embed) 854 | 855 | # overwrite, end 856 | json_content["userdata"][user_index] = json_user_content 857 | self.overwrite_json(json_content) 858 | 859 | return "success", "success" 860 | 861 | # 862 | # GIVE 863 | # 864 | 865 | async def give(self, user, channel, username, user_pfp, reception_user, amount, recept_uname): 866 | # load json 867 | json_file = open(self.pathToJson, "r") 868 | json_content = json.load(json_file) 869 | user_index, new_data = self.find_index_in_db(json_content["userdata"], user) 870 | reception_user_index, new_data = self.find_index_in_db(json_content["userdata"], reception_user) 871 | 872 | if new_data != "none": 873 | json_content["userdata"] = new_data 874 | 875 | json_user_content = json_content["userdata"][user_index] 876 | json_recept_content = json_content["userdata"][reception_user_index] 877 | 878 | user_cash = json_user_content["cash"] 879 | recept_cash = json_recept_content["cash"] 880 | 881 | if amount == "all": 882 | amount = user_cash 883 | if amount < 0: 884 | return "error", "❌ No negative values." 885 | else: 886 | amount = int(amount) 887 | if amount > user_cash: 888 | return "error", f"❌ You don't have that much money to give. You currently have {str(self.currency_symbol)} {'{:,}'.format(int(user_cash))} in the bank." 889 | 890 | json_user_content["cash"] -= amount 891 | json_recept_content["cash"] += amount 892 | 893 | # inform user 894 | color = self.discord_success_rgb_code 895 | embed = discord.Embed( 896 | description=f"✅ {recept_uname.mention} has received your {str(self.currency_symbol)} {'{:,}'.format(int(amount))}", 897 | color=color) 898 | embed.set_author(name=username, icon_url=user_pfp) 899 | await channel.send(embed=embed) 900 | 901 | # overwrite, end 902 | json_content["userdata"][user_index] = json_user_content 903 | json_content["userdata"][reception_user_index] = json_recept_content 904 | self.overwrite_json(json_content) 905 | 906 | return "success", "success" 907 | 908 | 909 | # 910 | # REMOVE GONE USERS / CLEAN LEADERBOARD 911 | # 912 | 913 | async def clean_leaderboard(self, server): 914 | # load json 915 | json_file = open(self.pathToJson, "r") 916 | json_content = json.load(json_file) 917 | 918 | json_users = json_content["userdata"] 919 | json_income_roles = json_content["income_roles"] 920 | amount_removed = 0 921 | pops = [] 922 | 923 | # we're gonna remove the user instance and the user params in collect etc. 924 | for user_index in range(len(json_users)): 925 | on_server = False 926 | for on_server_check in range(len(server.members)): 927 | if json_users[user_index]["user_id"] == server.members[on_server_check].id: 928 | on_server = True 929 | break 930 | 931 | if not on_server: 932 | # delete from the user section 933 | pop_index, b = self.find_index_in_db(json_users, json_users[user_index]["user_id"]) 934 | pops.append(pop_index) 935 | 936 | amount_removed += 1 937 | 938 | # basically minus because we go reverse, else we change the whole 939 | # list and then we cant work per index anymore ! 940 | # print(pops) 941 | pops.reverse() 942 | # print(pops) 943 | 944 | for index in range(len(pops)): 945 | 946 | # delete from user income role section 947 | for i in range(len(json_income_roles)): 948 | try: 949 | json_income_roles[i]["last_single_called"].pop(str(json_users[pops[index]]["user_id"])) 950 | except: 951 | pass 952 | 953 | del json_users[pops[index]] 954 | 955 | # overwrite, end 956 | json_content["userdata"] = json_users 957 | json_content["income_roles"] = json_income_roles 958 | self.overwrite_json(json_content) 959 | 960 | return "success", amount_removed 961 | 962 | 963 | # 964 | # LEADERBOARD 965 | # 966 | 967 | async def leaderboard(self, user, channel, username, full_name, page_number, mode_type, client): 968 | # load json 969 | json_file = open(self.pathToJson, "r") 970 | json_content = json.load(json_file) 971 | user_index, new_data = self.find_index_in_db(json_content["userdata"], user) 972 | 973 | if new_data != "none": 974 | json_content["userdata"] = new_data 975 | 976 | json_user_content = json_content["userdata"][user_index] 977 | 978 | """ 979 | sorting algorithm 980 | """ 981 | # yes, i could use a dict 982 | all_users = [] 983 | all_bal = [] 984 | i = 0 985 | for i in range(len(json_content["userdata"])): 986 | all_users.append(json_content["userdata"][i]["user_id"]) 987 | if mode_type == "-cash": 988 | all_bal.append(int(json_content["userdata"][i]["cash"])) 989 | elif mode_type == "-bank": 990 | all_bal.append(int(json_content["userdata"][i]["bank"])) 991 | else: # elif mode_type == "-total": 992 | # print(json_content["userdata"][i]["cash"] + json_content["userdata"][i]["bank"]) 993 | all_bal.append(int(json_content["userdata"][i]["cash"] + json_content["userdata"][i]["bank"])) 994 | # print(all_bal) 995 | # so, data is set, now sort 996 | 997 | i = -1 998 | while i <= len(all_bal): 999 | i += 1 1000 | try: 1001 | if all_bal[i] < all_bal[i + 1]: 1002 | # save the higher stats one into buffer 1003 | saved = all_bal[i] 1004 | # this one has lower stats, so move him right 1005 | all_bal[i] = all_bal[i + 1] 1006 | # the higher one (saved) takes that position 1007 | all_bal[i + 1] = saved 1008 | # repeat process, but for the player-names 1009 | saved = all_users[i] 1010 | all_users[i] = all_users[i + 1] 1011 | all_users[i + 1] = saved 1012 | i = -1 1013 | except: 1014 | pass 1015 | 1016 | """ 1017 | this seems to be whats taking the longest time while sorting 1018 | """ 1019 | 1020 | # use names instead of just ID, except if we cannot find names 1021 | # so for example if someone left the server 1022 | for i in range(len(all_users)): 1023 | try: 1024 | name_object = client.get_user(int(all_users[i])).name 1025 | # print(i, all_users[i], name_object) 1026 | actual_name = str(name_object) 1027 | if all_users[i] == user: 1028 | user_lb_position = i + 1 1029 | except: 1030 | actual_name = str(all_users[i]) 1031 | # update 1032 | all_users[i] = actual_name 1033 | try: 1034 | print("user is at position ", user_lb_position) 1035 | except Exception: 1036 | user_lb_position = 10000 # did not find him 1037 | 1038 | # making nice number formats 1039 | for i in range(len(all_bal)): 1040 | all_bal[i] = '{:,}'.format(all_bal[i]) 1041 | 1042 | # making the formatted output description 1043 | # number of pages which will be needed : 1044 | # we have 10 ranks per page 1045 | """ 1046 | btw before did this (idk why i did this and not just ceil ?) 1047 | if ".0" in str(page_count): page_count = int(page_count) 1048 | if not isinstance(page_count, int): 1049 | page_count += 1 1050 | """ 1051 | ranks_per_page = 10 1052 | page_count = math.ceil(len(all_bal) / ranks_per_page) 1053 | # page_count = (len(all_bal) + ranks_per_page - 1) 1054 | 1055 | # our selection ! 1056 | index_start = (page_number - 1) * ranks_per_page 1057 | index_end = index_start + ranks_per_page 1058 | user_selection = all_users[index_start: index_end] 1059 | bal_selection = all_bal[index_start: index_end] 1060 | 1061 | # making the formatted ! 1062 | if page_number == 1: 1063 | i = 0 1064 | else: 1065 | """ 1066 | this is because if we call page 2 we wanna start at 20 1067 | edit (26.04.24): page 2 should be starting at 10 obviously lol, 3 starts at 2. 1068 | without this we would have 1-10 on page 1 and then 21-30 on page 2. 1069 | """ 1070 | i = (page_number - 1) * ranks_per_page 1071 | 1072 | leaderboard_formatted = f"" 1073 | for i_i in range(len(user_selection)): 1074 | leaderboard_formatted += f"\n**{str(i + 1)}.** {user_selection[i_i]} • {str(self.currency_symbol)} {bal_selection[i_i]}" 1075 | i += 1 1076 | # making a nice output 1077 | if page_count == 1: 1078 | page_number = 1 1079 | elif page_number > page_count: 1080 | page_number = 1 1081 | 1082 | # inform user 1083 | color = self.discord_blue_rgb_code 1084 | embed = discord.Embed(description=f"\n\n{leaderboard_formatted}", color=color) 1085 | # same pfp as unbelievaboat uses 1086 | embed.set_author(name=full_name, 1087 | icon_url="https://media.discordapp.net/attachments/506838906872922145/506899959816126493/h5D6Ei0.png") 1088 | if user_lb_position == 1: 1089 | pos_name = "st" 1090 | elif user_lb_position == 2: 1091 | pos_name = "nd" 1092 | elif user_lb_position == 3: 1093 | pos_name = "rd" 1094 | else: 1095 | pos_name = "" 1096 | embed.set_footer( 1097 | text=f"Page {page_number}/{page_count} • Your leaderboard rank: {user_lb_position}{pos_name}") 1098 | await channel.send(embed=embed) 1099 | 1100 | return "success", "success" 1101 | 1102 | # 1103 | # MODULE INFO 1104 | # 1105 | 1106 | async def module(self, user, channel, module): 1107 | # load json 1108 | json_file = open(self.pathToJson, "r") 1109 | json_content = json.load(json_file) 1110 | 1111 | """ 1112 | variable_dict = { 1113 | "slut": 0, 1114 | "crime": 1, 1115 | "work": 2, 1116 | "rob": 3 1117 | } 1118 | """ 1119 | 1120 | if module not in self.variable_dict.keys() and module not in ["symbols", "currency_symbol"]: 1121 | possible = "slut, crime, work, rob, symbols" 1122 | return "error", f"❌ Module not found. Possibilites : {possible}" 1123 | 1124 | if module in ["symbols", "currency_symbol"]: 1125 | info_output = f"""Symbol:\nname: {json_content['symbols'][0]['name']}, value: emoji \"{json_content['symbols'][0]['symbol_emoji']}" """ 1126 | else: 1127 | module_index = self.variable_dict[module] 1128 | info_output = f"Module: **{module}** info:\nOutput as : ; \n```" 1129 | mod = json_content["variables"][module_index] 1130 | module_content = json_content["variables"][module_index] 1131 | for i in range(len(module_content)): 1132 | module_content_vars = list(json_content["variables"][module_index].keys())[i] 1133 | 1134 | info_output += f'\n"{module_content_vars}" ; {mod[module_content_vars]}' 1135 | info_output += "\n```\n**Note**: Delay is in minutes, proba is x%, percentages are in % too" 1136 | await channel.send(info_output) 1137 | 1138 | return "success", "success" 1139 | 1140 | # 1141 | # ADD-MONEY 1142 | # 1143 | 1144 | async def add_money(self, user, channel, username, user_pfp, reception_user, amount, recept_uname): 1145 | # load json 1146 | json_file = open(self.pathToJson, "r") 1147 | json_content = json.load(json_file) 1148 | reception_user_index, new_data = self.find_index_in_db(json_content["userdata"], reception_user) 1149 | 1150 | if new_data != "none": 1151 | json_content["userdata"] = new_data 1152 | 1153 | json_recept_content = json_content["userdata"][reception_user_index] 1154 | 1155 | json_recept_content["cash"] += int(amount) 1156 | 1157 | # inform user 1158 | color = self.discord_success_rgb_code 1159 | embed = discord.Embed( 1160 | description=f"✅ Added {str(self.currency_symbol)} {'{:,}'.format(int(amount))} to {recept_uname.mention}'s cash balance", 1161 | color=color) 1162 | embed.set_author(name=username, icon_url=user_pfp) 1163 | await channel.send(embed=embed) 1164 | 1165 | # overwrite, end 1166 | json_content["userdata"][reception_user_index] = json_recept_content 1167 | self.overwrite_json(json_content) 1168 | 1169 | return "success", "success" 1170 | 1171 | # 1172 | # REMOVE-MONEY 1173 | # 1174 | 1175 | async def remove_money(self, user, channel, username, user_pfp, reception_user, amount, recept_uname, mode): 1176 | # load json 1177 | json_file = open(self.pathToJson, "r") 1178 | json_content = json.load(json_file) 1179 | reception_user_index, new_data = self.find_index_in_db(json_content["userdata"], reception_user) 1180 | 1181 | if new_data != "none": 1182 | json_content["userdata"] = new_data 1183 | 1184 | json_recept_content = json_content["userdata"][reception_user_index] 1185 | 1186 | json_recept_content[mode] -= int(amount) 1187 | 1188 | # inform user 1189 | color = self.discord_success_rgb_code 1190 | embed = discord.Embed( 1191 | description=f"✅ Removed {str(self.currency_symbol)} {'{:,}'.format(int(amount))} from {recept_uname.mention}'s {mode} balance", 1192 | color=color) 1193 | embed.set_author(name=username, icon_url=user_pfp) 1194 | await channel.send(embed=embed) 1195 | 1196 | # overwrite, end 1197 | json_content["userdata"][reception_user_index] = json_recept_content 1198 | self.overwrite_json(json_content) 1199 | 1200 | return "success", "success" 1201 | 1202 | # 1203 | # EDIT VARIABLES 1204 | # 1205 | 1206 | async def edit_variables(self, user, channel, username, user_pfp, module_name, variable_name, new_value): 1207 | # load json 1208 | json_file = open(self.pathToJson, "r") 1209 | json_content = json.load(json_file) 1210 | 1211 | if module_name not in self.variable_dict.keys(): 1212 | return "error", "❌ module not found" 1213 | module_index = self.variable_dict[module_name] 1214 | 1215 | json_module_content = json_content["variables"][module_index] 1216 | try: 1217 | old_value = json_module_content[variable_name] 1218 | except: 1219 | return "error", f"❌ variable name of module {module_name} not found" 1220 | 1221 | # changing value 1222 | json_module_content[variable_name] = new_value 1223 | 1224 | # not asking for verification, would just have to reverse by another edit 1225 | # inform user 1226 | color = self.discord_success_rgb_code 1227 | embed = discord.Embed( 1228 | description=f"✅ Changed variable '{variable_name}' of module '{module_name}'\nBefore: '{old_value}'. Now: '{new_value}'", 1229 | color=color) 1230 | embed.set_author(name=username, icon_url=user_pfp) 1231 | await channel.send(embed=embed) 1232 | 1233 | # overwrite, end 1234 | json_content["variables"][module_index] = json_module_content 1235 | self.overwrite_json(json_content) 1236 | 1237 | return "success", "success" 1238 | 1239 | # 1240 | # EDIT CURRENCY SYMBOL 1241 | # 1242 | 1243 | async def change_currency_symbol(self, user, channel, username, user_pfp, new_emoji_name): 1244 | # load json 1245 | json_file = open(self.pathToJson, "r") 1246 | json_content = json.load(json_file) 1247 | 1248 | json_emoji = json_content["symbols"][0] 1249 | 1250 | old_value = json_emoji["symbol_emoji"] 1251 | 1252 | test_emoji = self.get_currency_symbol(True, new_emoji_name) 1253 | if test_emoji == "error": 1254 | return "error", "❌ Emoji not found." 1255 | 1256 | # changing value 1257 | json_emoji["symbol_emoji"] = new_emoji_name 1258 | 1259 | # not asking for verification, would just have to reverse by another edit 1260 | # inform user 1261 | color = self.discord_success_rgb_code 1262 | embed = discord.Embed(description=f"✅ Changed emoji from '{old_value}' to '{new_emoji_name}'", color=color) 1263 | embed.set_author(name=username, icon_url=user_pfp) 1264 | await channel.send(embed=embed) 1265 | 1266 | # overwrite, end 1267 | json_content["symbols"][0] = json_emoji 1268 | self.overwrite_json(json_content) 1269 | 1270 | return "success", "success" 1271 | 1272 | # 1273 | # EDIT CURRENCY SYMBOL 1274 | # 1275 | 1276 | async def set_income_reset(self, user, channel, username, user_pfp, new_income_reset): 1277 | # load json 1278 | json_file = open(self.pathToJson, "r") 1279 | json_content = json.load(json_file) 1280 | 1281 | # info: we dont need to check anything 1282 | # because itll be either true/false 1283 | # if it doesnt exist, we create it. if it does, we change it. simple. 1284 | 1285 | # changing value 1286 | json_content["symbols"][0]["income_reset"] = new_income_reset 1287 | 1288 | # not asking for verification, would just have to reverse by another edit 1289 | # inform user 1290 | color = self.discord_success_rgb_code 1291 | embed = discord.Embed(description=f"✅ Changed income-reset to `{new_income_reset}`", color=color) 1292 | embed.set_footer(text="info: if true (default), daily salary resets every day and does not accumulate.") 1293 | embed.set_author(name=username, icon_url=user_pfp) 1294 | await channel.send(embed=embed) 1295 | 1296 | # overwrite, end 1297 | self.overwrite_json(json_content) 1298 | 1299 | return "success", "success" 1300 | 1301 | """ 1302 | ITEM HANDLING 1303 | """ 1304 | 1305 | # 1306 | # CREATE NEW ITEM / create item 1307 | # 1308 | 1309 | async def create_new_item(self, item_display_name, item_name, cost, description, duration, stock, max_amount, roles_id_required, roles_id_to_give, 1310 | roles_id_to_remove, max_bal, reply_message, item_img_url, roles_id_excluded): 1311 | # load json 1312 | json_file = open(self.pathToJson, "r") 1313 | json_content = json.load(json_file) 1314 | 1315 | json_items = json_content["items"] 1316 | 1317 | for i in range(len(json_items)): 1318 | if json_items[i]["name"] == item_name: 1319 | return "error", "❌ Item with such name already exists." 1320 | 1321 | # calculate item duration 1322 | today = datetime.today() 1323 | # print(today) 1324 | expiration_date = today + timedelta(days=duration) 1325 | 1326 | # print("expiration date : ", expiration_date) 1327 | 1328 | json_items.append({ 1329 | "name": item_name, 1330 | "display_name": item_display_name, 1331 | "price": cost, 1332 | "description": description, 1333 | "duration": duration, 1334 | "amount_in_stock": stock, 1335 | "max_amount": max_amount, 1336 | "required_roles": roles_id_required, 1337 | "given_roles": roles_id_to_give, 1338 | "removed_roles": roles_id_to_remove, 1339 | "excluded_roles": roles_id_excluded, 1340 | "maximum_balance": max_bal, 1341 | "reply_message": reply_message, 1342 | "expiration_date": str(expiration_date), 1343 | "item_img_url": item_img_url 1344 | }) 1345 | 1346 | # overwrite, end 1347 | json_content["items"] = json_items 1348 | self.overwrite_json(json_content) 1349 | 1350 | return "success", "success" 1351 | 1352 | # 1353 | # REMOVE ITEM AKA DELETE ITEM 1354 | # 1355 | 1356 | async def remove_item(self, item_name): 1357 | # load json 1358 | json_file = open(self.pathToJson, "r") 1359 | json_content = json.load(json_file) 1360 | 1361 | json_items = json_content["items"] 1362 | item_found = item_index = 0 1363 | for i in range(len(json_items)): 1364 | if json_items[i]["name"] == item_name: 1365 | item_found = 1 1366 | item_index = i 1367 | if not item_found: 1368 | return "error", "❌ Item not found." 1369 | 1370 | # delete from the "items" section 1371 | json_items.pop(item_index) 1372 | 1373 | # delete for everyone who had it in their inventory 1374 | user_content = json_content["userdata"] 1375 | for i in range(len(user_content)): 1376 | # tricky 1377 | # i suppose the variable type will either be a string with "none" 1378 | # or a list with lists : ["item_name", amount], so items = [ [], [] ] etc 1379 | """ 1380 | info: on 11.01.24 added a break after pop(ii). 1381 | Only bug should be if user has 2 items with same name, but that shouldnt happen. 1382 | """ 1383 | if user_content[i]["items"] == "none": 1384 | pass 1385 | else: 1386 | try: 1387 | for ii in range(len(user_content[i]["items"])): 1388 | current_name = user_content[i]["items"][ii][0] 1389 | if current_name == item_name: 1390 | user_content[i]["items"].pop(ii) 1391 | break 1392 | except Exception as e: 1393 | print(e) 1394 | 1395 | # overwrite, end 1396 | json_content["items"] = json_items 1397 | self.overwrite_json(json_content) 1398 | 1399 | return "success", "success" 1400 | 1401 | # 1402 | # REMOVE ITEM FROM SPECIFIC USER's INVENTORY 1403 | # 1404 | 1405 | async def remove_user_item(self, user, channel, username, user_pfp, item_name, amount_removed, reception_user, recept_uname): 1406 | # load json 1407 | json_file = open(self.pathToJson, "r") 1408 | json_content = json.load(json_file) 1409 | reception_user_index, new_data = self.find_index_in_db(json_content["userdata"], reception_user) 1410 | 1411 | if new_data != "none": 1412 | json_content["userdata"] = new_data 1413 | 1414 | json_recept_content = json_content["userdata"][reception_user_index] 1415 | 1416 | # i just copied and adjusted the code snippet from give_item btw. 1417 | try: 1418 | if json_recept_content["items"] == "none": 1419 | return "error", f"❌ User does not have any items." 1420 | else: 1421 | worked = False 1422 | for ii_i in range(len(json_recept_content["items"])): 1423 | if json_recept_content["items"][ii_i][0] == item_name: 1424 | if (json_recept_content["items"][ii_i][1] - amount_removed) < 0: 1425 | return "error", f"❌ User does not have the necessary amount of items.\nInfo: has {json_recept_content['items'][ii_i][1]} items of that item." 1426 | json_recept_content["items"][ii_i][1] -= amount_removed 1427 | worked = True 1428 | break 1429 | if worked == False: 1430 | return "error", f"❌ User does not possess the specified item." 1431 | 1432 | except: 1433 | return "error", f"❌" 1434 | 1435 | # inform user 1436 | color = self.discord_success_rgb_code 1437 | embed = discord.Embed( 1438 | description=f"✅ Removed {'{:,}'.format(int(amount_removed))} {item_name} from {recept_uname.mention}.", 1439 | color=color) 1440 | embed.set_author(name=username, icon_url=user_pfp) 1441 | await channel.send(embed=embed) 1442 | 1443 | # overwrite, end 1444 | json_content["userdata"][reception_user_index] = json_recept_content 1445 | self.overwrite_json(json_content) 1446 | 1447 | return "success", "success" 1448 | 1449 | # 1450 | # BUY ITEM 1451 | # 1452 | 1453 | async def buy_item(self, user, channel, username, user_pfp, item_name, amount, user_roles, server_object, 1454 | user_object): 1455 | # load json 1456 | json_file = open(self.pathToJson, "r") 1457 | json_content = json.load(json_file) 1458 | 1459 | json_items = json_content["items"] 1460 | item_found = item_index = 0 1461 | for i in range(len(json_items)): 1462 | if json_items[i]["name"] == item_name: 1463 | item_found = 1 1464 | item_index = i 1465 | if not item_found: 1466 | return "error", "Item not found." 1467 | item = json_items[item_index] 1468 | # get variables 1469 | item_name = item_name 1470 | try: # compatibility 1471 | item_display_name = item["display_name"] 1472 | except: 1473 | item_display_name = item_name 1474 | item_price = item["price"] 1475 | req_roles = item["required_roles"] 1476 | give_roles = item["given_roles"] 1477 | rem_roles = item["removed_roles"] 1478 | try: 1479 | excluded_roles = item["excluded_roles"] 1480 | except: # compatibility 1481 | excluded_roles = ["none"] 1482 | max_bal = item["maximum_balance"] 1483 | remaining_stock = item["amount_in_stock"] 1484 | try: 1485 | max_amount = item["max_amount"] 1486 | except: 1487 | max_amount = "unlimited" 1488 | expiration_date = item["expiration_date"] 1489 | reply_message = item["reply_message"] 1490 | 1491 | # calculate expiration 1492 | today = datetime.today() 1493 | expire = datetime.strptime(expiration_date, "%Y-%m-%d %H:%M:%S.%f") 1494 | if today > expire: 1495 | return "error", f"❌ Item has already expired. Expiring date was {expiration_date}" 1496 | # else we're good 1497 | 1498 | # 1. check req roles 1499 | try: 1500 | if req_roles[0] == "none": 1501 | pass 1502 | else: 1503 | for i in range(len(req_roles)): 1504 | if int(req_roles[i]) not in user_roles: 1505 | return "error", f"❌ User does not seem to have all required roles." 1506 | except Exception as e: 1507 | print("1", e) 1508 | return "error", f"❌ Unexpected error." 1509 | 1510 | # 2. check excluded roles - meaning roles with which you CANT buy 1511 | try: 1512 | if excluded_roles[0] == "none": 1513 | pass 1514 | else: 1515 | for i in range(len(excluded_roles)): 1516 | if int(excluded_roles[i]) in user_roles: 1517 | return "error", f"❌ User possesses excluded role (id: {excluded_roles[i]})." 1518 | except Exception as e: 1519 | print("2", e) 1520 | return "error", f"❌ Unexpected error." 1521 | 1522 | ### BEFORE update, "check rem roles" and "check give roles" was located here. it seems that 1523 | ### the intended usage i had back then was to do that stuff once the item is bought. 1524 | ### thus this is now located below, after checking balance etc. 1525 | 1526 | # 4. check if enough money 1527 | sum_price = item_price * amount 1528 | sum_price = round(sum_price, 0) 1529 | user_index, new_data = self.find_index_in_db(json_content["userdata"], user) 1530 | user_content = json_content["userdata"][user_index] 1531 | user_cash = user_content["cash"] 1532 | if user_cash < sum_price: 1533 | return "error", f"❌ Not enough money in cash to purchase.\nto pay: {sum_price} ; in cash: {user_cash}" 1534 | 1535 | # 5. check if not too much money 1536 | user_bank = user_content["bank"] 1537 | if max_bal != "none": 1538 | if (user_bank + user_cash) > max_bal: 1539 | return "error", f"❌ You have too much money to purchase.\nnet worth: {'{:,}'.format(int(user_bank + user_cash))} ; max bal: {max_bal}" 1540 | 1541 | # 6. check if enough in stock or not 1542 | if remaining_stock != "unlimited": 1543 | if remaining_stock <= 0: 1544 | return "error", f"❌ Item not in stock." 1545 | elif amount > remaining_stock: 1546 | return "error", f" Not enough remaining in stock ({remaining_stock} remaining)." 1547 | 1548 | # 7. check if not too many items already owned / to be owned 1549 | user_item_amount = 0 # default value in case we have a bug 1550 | if user_content["items"] == "none": 1551 | user_item_amount = 0 1552 | else: 1553 | worked = False 1554 | for ii_i in range(len(user_content["items"])): 1555 | if user_content["items"][ii_i][0] == item_name: 1556 | user_item_amount = user_content["items"][ii_i][1] 1557 | worked = True 1558 | break 1559 | if not worked: # has items, just not the relevant one 1560 | user_item_amount = 0 1561 | 1562 | if max_amount != "unlimited": 1563 | if int(amount) >= int(max_amount) or int(user_item_amount + amount) >= int(max_amount) + 1: 1564 | available_to_buy = int(max_amount) - int(user_item_amount) 1565 | return "error", f"❌ You have too many items or would own too many.\nYou can buy **{'{:,}'.format(available_to_buy)}** {item_name}(s)" 1566 | 1567 | # 8. rem money, substract stock, add to inventory 1568 | user_content["cash"] -= sum_price 1569 | try: 1570 | item["amount_in_stock"] -= amount 1571 | except: 1572 | # in this case theres no limit so we dont substract anything 1573 | pass 1574 | 1575 | if user_content["items"] == "none": 1576 | user_content["items"] = [[item_name, amount]] 1577 | else: 1578 | needAppend = True 1579 | for i_i in range(len(user_content["items"])): 1580 | if user_content["items"][i_i][0] == item_name: 1581 | user_content["items"][i_i][1] += amount 1582 | needAppend = False 1583 | break 1584 | if needAppend: 1585 | user_content["items"].append([item_name, amount]) 1586 | 1587 | # 9. check remove roles 1588 | try: 1589 | if rem_roles[0] == "none": 1590 | pass 1591 | else: 1592 | for i in range(len(rem_roles)): 1593 | role = discord.utils.get(server_object.roles, id=int(rem_roles[i])) 1594 | try: 1595 | await user_object.remove_roles(role) 1596 | except: 1597 | continue 1598 | except Exception as e: 1599 | return "error", f"❌ Unexpected error." 1600 | 1601 | # 9. check give roles 1602 | try: 1603 | if give_roles[0] == "none": 1604 | pass 1605 | else: 1606 | for i in range(len(give_roles)): 1607 | role = discord.utils.get(server_object.roles, id=int(give_roles[i])) 1608 | try: 1609 | await user_object.add_roles(role) 1610 | except: 1611 | continue 1612 | 1613 | except Exception as e: 1614 | print("3", e) 1615 | return "error", f"❌ Unexpected error." 1616 | color = self.discord_blue_rgb_code 1617 | embed = discord.Embed( 1618 | description=f"You have bought {amount} {item_display_name} and paid {str(self.currency_symbol)} **{'{:,}'.format(int(sum_price))}**", 1619 | color=color) 1620 | embed.set_author(name=username, icon_url=user_pfp) 1621 | embed.set_footer(text=reply_message) 1622 | await channel.send(embed=embed) 1623 | 1624 | # overwrite, end 1625 | json_content["userdata"][user_index] = user_content 1626 | json_content["items"] = json_items 1627 | self.overwrite_json(json_content) 1628 | 1629 | return "success", "success" 1630 | 1631 | # 1632 | # GIVE ITEM 1633 | # 1634 | 1635 | async def give_item(self, user, channel, username, user_pfp, item_name, amount, reception_user, server_object, 1636 | user_object, recept_username, spawn_mode): 1637 | # load json 1638 | json_file = open(self.pathToJson, "r") 1639 | json_content = json.load(json_file) 1640 | user_index, new_data = self.find_index_in_db(json_content["userdata"], user) 1641 | reception_user_index, new_data = self.find_index_in_db(json_content["userdata"], reception_user) 1642 | recept_uname = recept_username 1643 | if new_data != "none": 1644 | json_content["userdata"] = new_data 1645 | 1646 | json_user_content = json_content["userdata"][user_index] 1647 | json_recept_content = json_content["userdata"][reception_user_index] 1648 | 1649 | try: 1650 | if not spawn_mode: # not doing this if an admin just spawns an item 1651 | if json_user_content["items"] == "none": 1652 | return "error", f"❌ You do not have any items to give" 1653 | else: 1654 | worked = False 1655 | for ii_i in range(len(json_user_content["items"])): 1656 | if json_user_content["items"][ii_i][0] == item_name: 1657 | if (json_user_content["items"][ii_i][1] - amount) < 0: 1658 | return "error", f"❌ You do not have enough items of that item to give." 1659 | json_user_content["items"][ii_i][1] -= amount 1660 | worked = True 1661 | break 1662 | if worked == False: 1663 | return "error", f"❌ You do not have that item to give" 1664 | else: 1665 | item_found = False 1666 | for i in range(len(json_content["items"])): 1667 | if json_content["items"][i]["name"] == item_name: 1668 | item_found = True 1669 | if not item_found: 1670 | return "error", "Item not found (needs to be created before spawning)." 1671 | 1672 | # so we should be good, now handling the reception side 1673 | if json_recept_content["items"] == "none": 1674 | json_recept_content["items"] = [[item_name, amount]] 1675 | else: 1676 | needAppend = True 1677 | for i_i in range(len(json_recept_content["items"])): 1678 | if json_recept_content["items"][i_i][0] == item_name: 1679 | json_recept_content["items"][i_i][1] += amount 1680 | needAppend = False 1681 | break 1682 | if needAppend: 1683 | json_recept_content["items"].append([item_name, amount]) 1684 | 1685 | except: 1686 | return "error", f"❌" 1687 | 1688 | # inform user 1689 | color = self.discord_success_rgb_code 1690 | if not spawn_mode: 1691 | embed = discord.Embed( 1692 | description=f"✅ {recept_uname.mention} has received {'{:,}'.format(int(amount))} {item_name} from you!", 1693 | color=color) 1694 | else: 1695 | embed = discord.Embed( 1696 | description=f"✅ {recept_uname.mention} has received {'{:,}'.format(int(amount))} {item_name} (spawned)!", 1697 | color=color) 1698 | embed.set_author(name=username, icon_url=user_pfp) 1699 | await channel.send(embed=embed) 1700 | 1701 | # overwrite, end 1702 | json_content["userdata"][user_index] = json_user_content 1703 | json_content["userdata"][reception_user_index] = json_recept_content 1704 | self.overwrite_json(json_content) 1705 | 1706 | return "success", "success" 1707 | 1708 | # 1709 | # USE ITEM 1710 | # 1711 | 1712 | async def use_item(self, user, channel, username, user_pfp, item_name, amount): 1713 | # load json 1714 | json_file = open(self.pathToJson, "r") 1715 | json_content = json.load(json_file) 1716 | user_index, new_data = self.find_index_in_db(json_content["userdata"], user) 1717 | if new_data != "none": 1718 | json_content["userdata"] = new_data 1719 | 1720 | json_user_content = json_content["userdata"][user_index] 1721 | 1722 | try: 1723 | if json_user_content["items"] == "none": 1724 | return "error", f"❌ You do not have any items" 1725 | else: 1726 | worked = False 1727 | for ii_i in range(len(json_user_content["items"])): 1728 | if json_user_content["items"][ii_i][0] == item_name: 1729 | if (json_user_content["items"][ii_i][1] - amount) < 0: 1730 | return "error", f"❌ You do not have enough items of that item to use." 1731 | json_user_content["items"][ii_i][1] -= amount 1732 | 1733 | # we will also add/append to a list for used items 1734 | try: 1735 | if json_user_content["used_items"] == "none": 1736 | json_user_content["used_items"] = [[item_name, amount]] 1737 | else: 1738 | needAppend = True 1739 | for i_i in range(len(json_user_content["used_items"])): 1740 | if json_user_content["used_items"][i_i][0] == item_name: 1741 | json_user_content["used_items"][i_i][1] += amount 1742 | needAppend = False 1743 | break 1744 | if needAppend: 1745 | json_user_content["used_items"].append([item_name, amount]) 1746 | except Exception as e: 1747 | # there is no used_items yet 1748 | # not really sure if this will work tho, might have to come back to this 1749 | json_user_content["used_items"] = [[item_name, amount]] 1750 | 1751 | 1752 | worked = True 1753 | break 1754 | if not worked: 1755 | return "error", f"❌ You do not have that item to give" 1756 | except Exception as e: 1757 | print(e) 1758 | return "error", f"❌ Unknown error, please contact an admin." 1759 | 1760 | 1761 | # inform user 1762 | color = self.discord_success_rgb_code 1763 | embed = discord.Embed( 1764 | description=f"✅ You have used {'{:,}'.format(int(amount))} {item_name}(s) !", 1765 | color=color) 1766 | embed.set_author(name=username, icon_url=user_pfp) 1767 | await channel.send(embed=embed) 1768 | 1769 | # overwrite, end 1770 | json_content["userdata"][user_index] = json_user_content 1771 | self.overwrite_json(json_content) 1772 | 1773 | return "success", "success" 1774 | 1775 | # 1776 | # CHECK INVENTORY 1777 | # 1778 | 1779 | async def check_inventory(self, user, channel, username, user_pfp, user_to_check, user_to_check_uname, user_to_check_pfp, page_number): 1780 | # load json 1781 | json_file = open(self.pathToJson, "r") 1782 | json_content = json.load(json_file) 1783 | 1784 | if user_to_check == "self": 1785 | user_index, new_data = self.find_index_in_db(json_content["userdata"], user) 1786 | user_content = json_content["userdata"][user_index] 1787 | else: # we re looking for a specific member 1788 | user_index, new_data = self.find_index_in_db(json_content["userdata"], user_to_check) 1789 | user_content = json_content["userdata"][user_index] 1790 | username = user_to_check_uname 1791 | user_pfp = user_to_check_pfp 1792 | 1793 | """ 1794 | we only care if we have any items owned, not 0 1795 | """ 1796 | items_old = user_content["items"] 1797 | if items_old != "none": 1798 | items = [] 1799 | for i in range(len(items_old)): 1800 | if items_old[i][1] > 0: 1801 | items.append(items_old[i]) 1802 | 1803 | # number of pages which will be needed : 1804 | # we have 10 items per page 1805 | items_per_page = 5 # change to 10 after 1806 | 1807 | # our selection ! 1808 | index_start = (page_number - 1) * items_per_page 1809 | index_end = index_start + items_per_page 1810 | items_selection = items[index_start: index_end] 1811 | page_count = math.ceil(len(items) / items_per_page) 1812 | else: 1813 | items = "none" 1814 | page_number = 1 1815 | page_count = 1 1816 | 1817 | if items == "none": 1818 | # inventory_checkup = "**Inventory empty. No items owned.**" 1819 | color = self.discord_blue_rgb_code 1820 | embed = discord.Embed(title="inventory", description="**Inventory empty. No items owned.**", color=color) 1821 | 1822 | else: 1823 | # inventory_checkup = f"" 1824 | color = self.discord_blue_rgb_code 1825 | embed = discord.Embed(title="inventory", color=color) 1826 | current_index = 1 if page_number == 1 else page_number * items_per_page # this is because if we call page 2 we wanna start at 20 1827 | for i in range(len(items_selection)): 1828 | # to get the display name 1829 | json_items = json_content["items"] 1830 | for ii in range(len(json_items)): 1831 | # print("checking item ", json_items[ii]["name"]) 1832 | if json_items[ii]["name"] == items_selection[i][0]: 1833 | item_index = ii 1834 | break 1835 | 1836 | try: 1837 | item_display_name = json_items[ii]["display_name"] 1838 | except: 1839 | item_display_name = items_selection[i][0] # if there is no display name, we show the normal name 1840 | # btw i use "ideographic space" [ ] for tab 1841 | # inventory_checkup += f"[{current_index}] Item: {item_display_name}\n  short name: {json_items[ii]['name']}\n  amount: `{items_selection[i][1]}`\n\n" 1842 | embed.add_field(name=f"[{current_index}] Item: {item_display_name}", 1843 | value=f"short name: `{json_items[ii]['name']}` " 1844 | f"amount: `{items_selection[i][1]}`", inline=False) 1845 | current_index += 1 1846 | 1847 | if page_count == 1: 1848 | page_number = 1 1849 | elif page_number > page_count: 1850 | page_number = 1 1851 | 1852 | embed.set_author(name=username, icon_url=user_pfp) 1853 | embed.set_footer(text=f"page {page_number} of {page_count}") 1854 | sent_embed = await channel.send(embed=embed) 1855 | 1856 | # overwrite, end 1857 | # not needed 1858 | 1859 | return "success", "success" 1860 | 1861 | # 1862 | # CATALOG 1863 | # 1864 | 1865 | async def catalog(self, user, channel, username, user_pfp, item_check, server_object): 1866 | # load json 1867 | json_file = open(self.pathToJson, "r") 1868 | json_content = json.load(json_file) 1869 | 1870 | items = json_content["items"] 1871 | catalog_final, max_items, current, finished = [], 10, 0, False 1872 | catalog_report = "__Items catalog:__\n```\n" 1873 | if item_check == "default_list": 1874 | for i in range(len(items)): 1875 | current += 1 1876 | try: 1877 | # print(current, max_items) 1878 | catalog_report += f"Item {i}: {items[i]['display_name']}\n price: {self.currency_symbol} {items[i]['price']}; short name <{items[i]['name']}>\n\n" 1879 | if current >= max_items: 1880 | # catalog_report += "\n```\n*For details about an item: use* `catalog `" 1881 | catalog_report += "\n```" 1882 | catalog_final.append(catalog_report) 1883 | catalog_report = "```" 1884 | current = 0 1885 | except: 1886 | await channel.send("compatbility error, please contact an admin.") 1887 | return "success", "success" 1888 | 1889 | #if current != 0: 1890 | # catalog_report += "\n*For details about an item: use* `catalog `" 1891 | #else: 1892 | catalog_report += "\n```\n*For details about an item: use* `catalog `" 1893 | catalog_final.append(catalog_report) 1894 | 1895 | else: 1896 | check, img_prob = 0, False 1897 | for i in range(len(items)): 1898 | if items[i]["name"] == item_check: 1899 | check = 1 1900 | item_index = i 1901 | if not check: 1902 | return "error", "❌ Item not found." 1903 | else: # not needed, but for readability 1904 | 1905 | if items == "none": 1906 | # inventory_checkup = "**Inventory empty. No items owned.**" 1907 | color = self.discord_blue_rgb_code 1908 | embed = discord.Embed(title="inventory", description="**Inventory empty. No items owned.**", 1909 | color=color) 1910 | 1911 | else: 1912 | color = self.discord_blue_rgb_code 1913 | 1914 | 1915 | try: 1916 | embed = discord.Embed(title=f"catalog: {items[item_index]['display_name']}", color=color) 1917 | except: 1918 | embed = discord.Embed(title=f"catalog: item {items[item_index]['name']}", color=color) 1919 | 1920 | req_roles = "" 1921 | 1922 | for ii in range(len(items[item_index]["required_roles"])): 1923 | if items[item_index]["required_roles"][ii] in ["none", ""]: 1924 | req_roles += "none" 1925 | else: 1926 | role = discord.utils.get(server_object.roles, id=int(items[item_index]["required_roles"][ii])) 1927 | req_roles += f"{str(role.mention)} " 1928 | 1929 | excluded_roles = "" 1930 | try: # compatibility thingy 1931 | for ii in range(len(items[item_index]["excluded_roles"])): 1932 | if items[item_index]["excluded_roles"][ii] in ["none", ""]: 1933 | excluded_roles += "none" 1934 | else: 1935 | role = discord.utils.get(server_object.roles, id=int(items[item_index]["excluded_roles"][ii])) 1936 | excluded_roles += f"{str(role.mention)} " 1937 | except Exception as e: 1938 | print(f"Error for required roles: {e} - (prob compatibility thingy).") 1939 | excluded_roles += "none" 1940 | 1941 | give_roles = "" 1942 | for iii in range(len(items[item_index]["given_roles"])): 1943 | if items[item_index]["given_roles"][iii] in ["none", ""]: 1944 | give_roles += "none" 1945 | else: 1946 | role = discord.utils.get(server_object.roles, id=int(items[item_index]["given_roles"][iii])) 1947 | give_roles += f"{str(role.mention)} " 1948 | 1949 | rem_roles = "" 1950 | for iiii in range(len(items[item_index]["removed_roles"])): 1951 | if items[item_index]["removed_roles"][iiii] in ["none", ""]: 1952 | rem_roles += "none" 1953 | else: 1954 | role = discord.utils.get(server_object.roles, id=int(items[item_index]["removed_roles"][iiii])) 1955 | rem_roles += f"{str(role.mention)} " 1956 | 1957 | if int(str(datetime.strptime(items[item_index]['expiration_date'], '%Y-%m-%d %H:%M:%S.%f'))[ 1958 | :4]) >= 2100: 1959 | left_time = "never" 1960 | else: 1961 | left_time = str(items[item_index]['expiration_date'])[:10] 1962 | 1963 | # check for old version that dont have a max amount yet 1964 | try: 1965 | max_amount = items[item_index]['max_amount'] 1966 | except: 1967 | max_amount = 0 1968 | 1969 | try: 1970 | embed.add_field(name=f"Item name:", value=f"{items[item_index]['display_name']}", inline=False) 1971 | embed.add_field(name=f"Item short name:", value=f"`{items[item_index]['name']}`", inline=True) 1972 | embed.add_field(name=f"Item price:", value=f"{items[item_index]['price']}", inline=True) 1973 | embed.add_field(name=f"In stock:", value=f"{items[item_index]['amount_in_stock']}", inline=True) 1974 | embed.add_field(name=f"Max amount you can own:", value=f"{max_amount}", inline=False) 1975 | embed.add_field(name=f"Item description:", value=f"{items[item_index]['description']}", inline=False) 1976 | embed.add_field(name=f"Remaining time:", value=f"item expires {left_time}", inline=True) 1977 | embed.add_field(name=f"Max balance to purchase:", value=f"{self.currency_symbol} {items[item_index]['maximum_balance']}", inline=False) 1978 | embed.add_field(name=f"Roles:", 1979 | value=f"Required roles: {req_roles} " 1980 | f"Excluded roles: {excluded_roles} " 1981 | f"Given roles: {give_roles} " 1982 | f"Removed roles: {rem_roles}", inline=False) 1983 | try: 1984 | if items[item_index]['item_img_url'] != "EMPTY": 1985 | embed.set_thumbnail(url=items[item_index]['item_img_url']) 1986 | except: 1987 | # basically we re trying to check if theres an image in the item object 1988 | # but we also try to set it as a thumbnail, and if that fails 1989 | # we wont replace it but warn the user with a specialised footer 1990 | # yes this is ugly. Itll do for now. 1991 | try: 1992 | if items[item_index]['item_img_url'] != "EMPTY": img_prob = True 1993 | except: 1994 | img_prob = False 1995 | except Exception as error_code: 1996 | print(error_code) 1997 | await channel.send("# warning:\nfallback mode; This should not happen. Try to contact a bot admin (or see github at https://github.com/NoNameSpecified/UnbelievaBoat-Python-Bot)") 1998 | catalog_report += f"Item short name: <{items[item_index]['name']}>\n" \ 1999 | f"Item price: {items[item_index]['price']}\n" \ 2000 | f"Item description: {items[item_index]['description']}\n" \ 2001 | f"Remaining time: item expires {left_time}\n" \ 2002 | f"Amount remaining: {items[item_index]['amount_in_stock']} in stock\n" \ 2003 | f"Max amount you can own: {items[item_index]['max_amount']}\n" \ 2004 | f"Maximum balance to purchase: {self.currency_symbol} {items[item_index]['maximum_balance']}\n" \ 2005 | f"Required roles: {req_roles}\n" \ 2006 | f"Given roles: {give_roles}\n" \ 2007 | f"Removed roles: {rem_roles}\n" 2008 | await channel.send(catalog_report) 2009 | return "success", "success" 2010 | 2011 | # embed.set_author(name=username, icon_url=user_pfp) 2012 | embed.set_footer(text="WARNING: URL for img was not found. Could be deprecated\nPlease look into the json file manually or contact an admin.") if img_prob else embed.set_footer(text="Info: always use the short name for commands.") 2013 | sent_embed = await channel.send(embed=embed) 2014 | return "success", "success" 2015 | for i in range(len(catalog_final)): 2016 | await channel.send(catalog_final[i]) 2017 | 2018 | # overwrite, end 2019 | # not needed 2020 | 2021 | return "success", "success" 2022 | 2023 | # 2024 | # ROLE INCOMES - NEW ONE 2025 | # 2026 | 2027 | async def new_income_role(self, user, channel, username, user_pfp, income_role_id, income): 2028 | # load json 2029 | json_file = open(self.pathToJson, "r") 2030 | json_content = json.load(json_file) 2031 | 2032 | json_income_roles = json_content["income_roles"] 2033 | 2034 | for i in range(len(json_income_roles)): 2035 | if json_income_roles[i]["role_id"] == income_role_id: 2036 | return "error", "❌ Role already exists as income role." 2037 | 2038 | now = str(datetime.now()) 2039 | json_income_roles.append({ 2040 | "role_id": income_role_id, 2041 | "role_income": income, 2042 | "last_single_called": {}, 2043 | "last_updated": now 2044 | }) 2045 | 2046 | color = self.discord_blue_rgb_code 2047 | embed = discord.Embed( 2048 | description=f"New income role added.\nrole_id : {income_role_id}, income : {str(self.currency_symbol)} **{'{:,}'.format(int(income))}**", 2049 | color=color) 2050 | embed.set_author(name=username, icon_url=user_pfp) 2051 | embed.set_footer(text="smooth") 2052 | await channel.send(embed=embed) 2053 | 2054 | # overwrite, end 2055 | json_content["income_roles"] = json_income_roles 2056 | self.overwrite_json(json_content) 2057 | 2058 | return "success", "success" 2059 | 2060 | # 2061 | # ROLE INCOMES - REMOVE ONE 2062 | # 2063 | 2064 | async def remove_income_role(self, user, channel, username, user_pfp, income_role_id): 2065 | # load json 2066 | json_file = open(self.pathToJson, "r") 2067 | json_content = json.load(json_file) 2068 | 2069 | json_income_roles = json_content["income_roles"] 2070 | role_found = role_index = 0 2071 | for i in range(len(json_income_roles)): 2072 | if json_income_roles[i]["role_id"] == income_role_id: 2073 | role_found = 1 2074 | role_index = i 2075 | if not role_found: 2076 | return "error", "❌ Role not found." 2077 | 2078 | # delete from the "items" section 2079 | json_income_roles.pop(role_index) 2080 | 2081 | # overwrite, end 2082 | json_content["income_roles"] = json_income_roles 2083 | self.overwrite_json(json_content) 2084 | 2085 | return "success", "success" 2086 | 2087 | # 2088 | # ROLE INCOMES - LIST 2089 | # 2090 | 2091 | async def list_income_roles(self, user, channel, username, user_pfp, server_object): 2092 | # load json 2093 | json_file = open(self.pathToJson, "r") 2094 | json_content = json.load(json_file) 2095 | 2096 | json_income_roles = json_content["income_roles"] 2097 | 2098 | role_list_report = f"__Income Roles List:__\n\n" 2099 | 2100 | for i in range(len(json_income_roles)): 2101 | role = discord.utils.get(server_object.roles, id=int(json_income_roles[i]["role_id"])) 2102 | ping_role = f"<@&{json_income_roles[i]['role_id']}>" 2103 | 2104 | role_list_report += f"Role name: {ping_role}\n" \ 2105 | f"Role income: {self.currency_symbol} {'{:,}'.format(json_income_roles[i]['role_income'])}\n\n" 2106 | 2107 | role_list_report += "---------------------------------" 2108 | 2109 | await channel.send(role_list_report, silent=True) 2110 | 2111 | # overwrite, end 2112 | # not needed 2113 | 2114 | return "success", "success" 2115 | 2116 | # 2117 | # ROLE INCOMES - UPDATE INCOMES 2118 | # 2119 | # okay were gonna change it to an hourly income (10.06.2023) 2120 | 2121 | async def update_incomes(self, user, channel, username, user_pfp, server_object): 2122 | # load json 2123 | json_file = open(self.pathToJson, "r") 2124 | json_content = json.load(json_file) 2125 | 2126 | json_income_roles = json_content["income_roles"] 2127 | user_content = json_content["userdata"] 2128 | 2129 | # pretty straight forward i think. 2130 | # first, we go into each role object 2131 | # then we check in everyones roles if they have the role 2132 | 2133 | role_error = 0 # if a role is deleted or so 2134 | 2135 | for role_index in range(len(json_income_roles)): 2136 | role_id = json_income_roles[role_index]["role_id"] 2137 | 2138 | # new edit for hourly income: 2139 | # edit new new edit for daily again.. 2140 | now = datetime.now() 2141 | # below could be changed because we need single one for every user now... 2142 | last_income_update_string = json_income_roles[role_index]["last_updated"] 2143 | # 2144 | 2145 | # get a timeobject from the string 2146 | last_income_update = datetime.strptime(last_income_update_string, '%Y-%m-%d %H:%M:%S.%f') 2147 | # calculate difference, see if it works 2148 | passed_time = now - last_income_update 2149 | # passed_time_final = passed_time.total_seconds() // 3600.0 2150 | passed_time_final = passed_time.days 2151 | 2152 | try: 2153 | role = discord.utils.get(server_object.roles, id=int(role_id)) 2154 | except: 2155 | role_error += 1 2156 | continue 2157 | 2158 | for member in role.members: 2159 | try: 2160 | # also to create user in case he isnt registered yet 2161 | user_index, new_data = self.find_index_in_db(json_content["userdata"], member.id) 2162 | 2163 | json_user_content = json_content["userdata"][user_index] 2164 | json_income_roles[role_index]["last_updated"] = str(now) 2165 | income_total = (json_income_roles[role_index]["role_income"] * int(passed_time_final)) 2166 | json_user_content["bank"] += income_total 2167 | # overwrite 2168 | json_content["userdata"][user_index] = json_user_content 2169 | 2170 | except: 2171 | pass 2172 | await channel.send(f"{role.mention}, you have received your income ({self.currency_symbol} {'{:,}'.format(int(income_total))}) !", silent=True) 2173 | 2174 | 2175 | # overwrite, end 2176 | json_content["income_roles"] = json_income_roles 2177 | self.overwrite_json(json_content) 2178 | 2179 | if role_error == 0: 2180 | return "success", "success" 2181 | else: 2182 | return "error", f"error for `{role_error} role(s)`, maybe some got deleted?. Else the command successed." 2183 | 2184 | # 2185 | # SOLO ROLE INCOME - UPDATE INCOMES SOLO 2186 | # aka GET SALARY 2187 | 2188 | async def update_incomes_solo(self, user, channel, username, user_pfp, server_object, user_roles): 2189 | # load json 2190 | json_file = open(self.pathToJson, "r") 2191 | json_content = json.load(json_file) 2192 | user_index, new_data = self.find_index_in_db(json_content["userdata"], user) 2193 | 2194 | json_income_roles = json_content["income_roles"] 2195 | user_content = json_content["userdata"] 2196 | 2197 | # this is the other way around than the global update income 2198 | 2199 | role_ping_complete = [] 2200 | hours_remaining = "24" 2201 | no_money = True 2202 | income_total = 0 2203 | received_instances = 0 2204 | for role in user_roles: 2205 | for role_index in range(len(json_income_roles)): 2206 | role_id = json_income_roles[role_index]["role_id"] 2207 | if int(role) == int(role_id): 2208 | no_money = False 2209 | 2210 | 2211 | # new edit for daily income: 2212 | now = datetime.now() 2213 | # now = datetime.strptime("2024-02-11 00:01:33.884845", '%Y-%m-%d %H:%M:%S.%f') 2214 | 2215 | # first check if he already got one at all 2216 | try: 2217 | json_user_content = json_content["userdata"][user_index] 2218 | 2219 | # role_ping_complete.append(discord.utils.get(server_object.roles, id=int(role_id))) 2220 | 2221 | """ 2222 | 30.12.23: new edit. By default now, users will get a daily salary 2223 | and will have to retrieve it daily. You can also change that tho 2224 | by changing "income_reset" to true in the json. 2225 | Because this is an update and we want compatibility with older versions, 2226 | we will need to try and if not write a income_reset. 2227 | """ 2228 | """ 2229 | 08.02.24: new new edit. Now, payday resets GLOBALLY (not one day since you specifically did) 2230 | """ 2231 | # true by default 2232 | income_reset, new_day = True, False 2233 | try: 2234 | if json_content["symbols"][0]["income_reset"] == "false": income_reset = False 2235 | except: 2236 | # if not yet updated, we add this to json 2237 | json_content["symbols"][0]["income_reset"] = "true" 2238 | # get the current day 2239 | try: 2240 | last_global_update_string = json_content["symbols"][0]["global_collect"] 2241 | last_global_update = datetime.strptime(last_global_update_string, '%Y-%m-%d %H:%M:%S.%f') 2242 | 2243 | last_single_called = json_income_roles[role_index]["last_single_called"][str(user)] 2244 | last_single = int(datetime.strptime(last_single_called, '%Y-%m-%d %H:%M:%S.%f').strftime("%d")) 2245 | 2246 | today_day, last_day = int(now.strftime("%d")), int(last_global_update.strftime("%d")) 2247 | max_days = calendar.monthrange(int(now.strftime("%Y")), int(now.strftime("%m")))[1] 2248 | # print(today_day, last_day, max_days) 2249 | # print(last_single, today_day, last_day) 2250 | if today_day > max_days: last_day = 1 2251 | if last_single < last_day: 2252 | new_day = True 2253 | 2254 | # for example if i last called on 08th JANUARY and today is 07th FEBRUARY 2255 | # the check above would say nope, so this is to fix that 2256 | if datetime.strptime(last_single_called, '%Y-%m-%d %H:%M:%S.%f') < last_global_update and last_single > last_day: 2257 | new_day = True 2258 | 2259 | else: 2260 | hour_rem = 24 - int(now.strftime('%H')) - 1 2261 | min_rem_raw = 0 if 60 - int(now.strftime('%M')) == 60 else 60 - int(now.strftime('%M')) 2262 | min_rem = f"0{min_rem_raw}" if min_rem_raw < 10 else min_rem_raw 2263 | hours_remaining = f"{hour_rem}:{min_rem}" 2264 | except Exception as error_code: 2265 | print(error_code) 2266 | await channel.send("setting up") 2267 | json_content["symbols"][0]["global_collect"] = str(now) 2268 | new_day = True 2269 | 2270 | 2271 | if income_reset and new_day: 2272 | # you only get it DAILY, other than that it resets ! 2273 | income_total += json_income_roles[role_index]["role_income"] 2274 | json_income_roles[role_index]["last_single_called"][str(user)] = str(now) 2275 | received_instances += 1 2276 | json_content["symbols"][0]["global_collect"] = str(now) 2277 | 2278 | except Exception as error_code: # he didn't retrieve a salary yet 2279 | print(error_code) 2280 | await channel.send("creating your first entry...") 2281 | json_income_roles[role_index]["last_single_called"][str(user)] = str(now) # removed on 08.02. update 2282 | # also to create user in case he isnt registered yet 2283 | income_total += json_income_roles[role_index]["role_income"] 2284 | received_instances += 1 2285 | 2286 | # role_ping_complete.append(discord.utils.get(server_object.roles, id=int(role_id))) 2287 | 2288 | json_user_content = json_content["userdata"][user_index] 2289 | json_user_content["bank"] += income_total 2290 | # overwrite 2291 | json_content["userdata"][user_index] = json_user_content 2292 | json_content["income_roles"] = json_income_roles 2293 | 2294 | if no_money: 2295 | await channel.send("You have no income roles!") 2296 | else: 2297 | if int(income_total) != 0: 2298 | await channel.send(f"You have received your income ({self.currency_symbol} {'{:,}'.format(int(income_total))}) from a total of {received_instances} different roles!", silent=True) 2299 | else: 2300 | await channel.send(f"`You already collected! Reset in: {hours_remaining} hours.`", silent=True) 2301 | 2302 | # overwrite, end 2303 | self.overwrite_json(json_content) 2304 | 2305 | return "success", "success" 2306 | 2307 | 2308 | 2309 | # 2310 | # REMOVE MONEY BY ROLE 2311 | # 2312 | 2313 | async def remove_money_role(self, user, channel, username, user_pfp, server_object, income_role, amount_removed): 2314 | # load json 2315 | json_file = open(self.pathToJson, "r") 2316 | json_content = json.load(json_file) 2317 | 2318 | json_income_roles = json_content["income_roles"] 2319 | 2320 | # pretty straight forward i think. 2321 | # first, we go into each role object 2322 | # then we check in everyones roles if they have the role 2323 | 2324 | role = discord.utils.get(server_object.roles, id=int(income_role)) 2325 | for member in role.members: 2326 | try: 2327 | # also to create user in case he isnt registered yet 2328 | user_index, new_data = self.find_index_in_db(json_content["userdata"], member.id) 2329 | 2330 | json_user_content = json_content["userdata"][user_index] 2331 | if json_user_content["bank"] - int(amount_removed) < 0: 2332 | json_user_content["bank"] = 0 2333 | else: 2334 | json_user_content["bank"] -= int(amount_removed) 2335 | # overwrite 2336 | json_content["userdata"][user_index] = json_user_content 2337 | 2338 | except: 2339 | pass 2340 | 2341 | # inform user 2342 | color = self.discord_success_rgb_code 2343 | embed = discord.Embed( 2344 | description=f"✅ You have removed {self.currency_symbol} {'{:,}'.format(int(amount_removed))} from a total of {'{:,}'.format(int(len(role.members)))} users with that role !", 2345 | color=color) 2346 | embed.set_author(name=username, icon_url=user_pfp) 2347 | await channel.send(embed=embed) 2348 | 2349 | # overwrite, end 2350 | json_content["income_roles"] = json_income_roles 2351 | self.overwrite_json(json_content) 2352 | 2353 | return "success", "success" 2354 | 2355 | # 2356 | # ECONOMY STATS 2357 | # 2358 | 2359 | async def economy_stats(self, user, channel, username, user_pfp, server_object): 2360 | # load json 2361 | json_file = open(self.pathToJson, "r") 2362 | json_content = json.load(json_file) 2363 | 2364 | total_cash, total_bank, total_total = 0, 0, 0 2365 | 2366 | for i in range(len(json_content["userdata"])): 2367 | total_cash += json_content["userdata"][i]["cash"] 2368 | total_bank += json_content["userdata"][i]["bank"] 2369 | 2370 | total_total = total_cash + total_bank 2371 | 2372 | # inform user 2373 | color = self.discord_blue_rgb_code 2374 | embed = discord.Embed(color=color) 2375 | embed.add_field(name=f"**Total Cash:**", value=f"{self.currency_symbol} {'{:,}'.format(int(total_cash))}", inline=False) 2376 | embed.add_field(name=f"**Total Bank:**", value=f"{self.currency_symbol} {'{:,}'.format(int(total_bank))}", inline=False) 2377 | embed.add_field(name=f"**Total:**", value=f"{self.currency_symbol} {'{:,}'.format(int(total_total))}", inline=False) 2378 | embed.set_author(name="Economy Stats", icon_url="https://upload.wikimedia.org/wikipedia/commons/5/5e/Map_symbol_museum_02.png") 2379 | await channel.send(embed=embed) 2380 | 2381 | return "success", "success" 2382 | -------------------------------------------------------------------------------- /src/database/database.json: -------------------------------------------------------------------------------- 1 | { 2 | "userdata": [ 3 | { 4 | "user_id": 100000000000000000, 5 | "cash": 100.0, 6 | "bank": 100.0, 7 | "items": "none", 8 | "used_items": "none", 9 | "last_slut": "2021-01-01 00:00:00.0", 10 | "last_work": "2021-01-01 00:00:00.0", 11 | "last_crime": "2021-01-01 00:00:00.0", 12 | "last_rob": "2021-01-01 00:00:00.0" 13 | } 14 | ], 15 | "variables": [ 16 | { 17 | "name": "slut", 18 | "delay": 10, 19 | "min_revenue": 50, 20 | "max_revenue": 400, 21 | "proba": 50, 22 | "win_phrases": [ 23 | "You made", 24 | "Your dad likes it so much he gives you" 25 | ], 26 | "lose_phrases": [ 27 | "You were fined", 28 | "Your uncle didn't like the encounter. You pay" 29 | ], 30 | "min_lose_amount_percentage": 2, 31 | "max_lose_amount_percentage": 5 32 | }, 33 | { 34 | "name": "crime", 35 | "delay": 60, 36 | "min_revenue": 100, 37 | "max_revenue": 1200, 38 | "proba": 30, 39 | "win_phrases": [ 40 | "You commited a crime and got", 41 | "You robbed a bank and got" 42 | ], 43 | "lose_phrases": [ 44 | "You were fined", 45 | "MacGyver finds you, you pay" 46 | ], 47 | "min_lose_amount_percentage": 10, 48 | "max_lose_amount_percentage": 20 49 | }, 50 | { 51 | "name": "work", 52 | "delay": 10, 53 | "min_revenue": 51, 54 | "max_revenue": 200, 55 | "win_phrases": [ 56 | "You worked at SubWay and made", 57 | "You helped someone do his homework and got" 58 | ] 59 | }, 60 | { 61 | "name": "rob", 62 | "delay": 45, 63 | "proba": 50, 64 | "min_gain_amount_percentage": 10, 65 | "max_gain_amount_percentage": 20, 66 | "min_lose_amount_percentage": 10, 67 | "max_lose_amount_percentage": 20, 68 | "win_phrases": [ 69 | "You robbed and got" 70 | ], 71 | "lose_phrases": [ 72 | "You were caught robbing and have to pay" 73 | ] 74 | } 75 | ], 76 | "symbols": [ 77 | { 78 | "name": "currency_symbol", 79 | "symbol_emoji": "my_currency_emoji_clear_name_only", 80 | "income_reset": "true", 81 | "global_collect": "2024-02-08 19:34:36.648900" 82 | } 83 | ], 84 | "items": [], 85 | "income_roles": [] 86 | } 87 | -------------------------------------------------------------------------------- /src/game_libs/blackjack/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | START OF BJACK 3 | BLACKJACK GAME found on https://gist.github.com/StephanieSunshine/d34039857566d957f26cea8277b3ac65, 4 | not creating one because it would take too much time and isnt the purpose of this 5 | but changing the code to implement it with our discord bot 6 | """ 7 | 8 | import random, discord 9 | 10 | 11 | class Card: 12 | def __init__(self, rank, suit): 13 | self.rank = rank 14 | self.suit = suit 15 | self.cardName = {1: 'Ace', 2: 'Two', 3: 'Three', 4: 'Four', 5: 'Five', 6: 'Six', 7: 'Seven', 8: 'Eight', 9: 'Nine', 10: 'Ten', 11: 'Jack', 12: 'Queen', 13: 'King'} 16 | self.cardSuit = {'c': 'Clubs', 'h': 'Hearts', 's': 'Spades', 'd': 'Diamonds'} 17 | 18 | def __str__(self): 19 | return (self.cardName[self.rank] + " Of " + self.cardSuit[self.suit]) 20 | 21 | def getRank(self): 22 | return (self.rank) 23 | 24 | def getSuit(self): 25 | return (self.suit) 26 | 27 | def BJValue(self): 28 | if self.rank > 9: 29 | return (10) 30 | else: 31 | return (self.rank) 32 | 33 | 34 | # what will be called to play the game 35 | class blackjack_discord_implementation: 36 | def __init__(self, bot, channel, currency_symbol): 37 | self.currency_symbol = currency_symbol 38 | self.bot = bot 39 | self.channel = channel 40 | # used below for edit tracking 41 | self.loopCount = -1 42 | self.cardName = {1: 'Ace', 2: 'Two', 3: 'Three', 4: 'Four', 5: 'Five', 6: 'Six', 7: 'Seven', 8: 'Eight', 9: 'Nine', 10: 'Ten', 11: 'Jack', 12: 'Queen', 13: 'King'} 43 | self.cardSuit = {'c': 'Clubs', 'h': 'Hearts', 's': 'Spades', 'd': 'Diamonds'} 44 | 45 | def handCount(self, hand): 46 | handCount = 0 47 | for card in hand: 48 | handCount += card.BJValue() 49 | return (handCount) 50 | 51 | async def get_user_input(self, message): 52 | # we want an answer from the guy who wants to give an answer 53 | answer = await self.bot.wait_for("message", check=lambda response: response.author == message.author) 54 | answer = answer.content 55 | # clean input 56 | answer = answer.lower().strip() 57 | # we only want hit or stand, nothing else, and still wait after that tho 58 | if answer not in ["hit", "stand"]: 59 | return "none" 60 | 61 | return answer 62 | 63 | async def play(self, bot, channel, username, user_pfp, message, bet): 64 | self.bot = bot 65 | deck = [] 66 | suits = ['c', 'h', 'd', 's'] 67 | score = {'computer': 0, 'human': 0} 68 | hand = {'computer': [], 'human': []} 69 | 70 | for suit in suits: 71 | for rank in range(1, 14): 72 | deck.append(Card(rank, suit)) 73 | 74 | keepPlaying = True 75 | 76 | while keepPlaying: 77 | random.shuffle(deck) 78 | random.shuffle(deck) 79 | random.shuffle(deck) 80 | 81 | # Deal Cards 82 | 83 | hand['human'].append(deck.pop(0)) 84 | hand['computer'].append(deck.pop(0)) 85 | 86 | hand['human'].append(deck.pop(0)) 87 | hand['computer'].append(deck.pop(0)) 88 | 89 | playHuman = True 90 | bustedHuman = False 91 | 92 | while playHuman: 93 | self.loopCount += 1 94 | 95 | # initial EMBED sent to the client 96 | if self.loopCount == 0: 97 | color = discord.Color.from_rgb(3, 169, 244) 98 | firstEmbed = discord.Embed(description=f"Type `hit` to draw another card, or `stand` to pass.", color=color) 99 | firstEmbed.set_author(name=username, icon_url=user_pfp) 100 | firstEmbed.add_field(name="**Your hand**", value=f"X X\nValue {self.handCount(hand['human'])}", inline=True) 101 | firstEmbed.add_field(name="**Dealer shows**", value=f"{str(hand['computer'][-1])}\nValue ?", inline=True) 102 | firstEmbed.set_footer(text="Cards remaining: 999") 103 | sentFirstEmbed = await channel.send(embed=firstEmbed) 104 | # which we will edit 105 | else: 106 | 107 | color = discord.Color.from_rgb(3, 169, 244) 108 | newEmbed = discord.Embed(description=f"Type `hit` to draw another card, or `stand` to pass.", color=color) 109 | newEmbed.set_author(name=username, icon_url=user_pfp) 110 | newEmbed.add_field(name="**Your hand**", value=f"X X\nValue {self.handCount(hand['human'])}", inline=True) 111 | newEmbed.add_field(name="**Dealer shows**", value=f"{str(hand['computer'][-1])}\nValue ?", inline=True) 112 | newEmbed.set_footer(text="Cards remaining: 999") 113 | await sentFirstEmbed.edit(embed=newEmbed) 114 | 115 | 116 | # print("right now at ", self.handCount(hand['human'])) 117 | if self.handCount(hand['human']) == 21: 118 | # print("blackjack !") 119 | playHuman = False 120 | break 121 | 122 | inputCycle = True 123 | userInput = '' 124 | 125 | # wait until good input 126 | while inputCycle: 127 | # now, what does the user want ? 128 | userInput = await self.get_user_input(message) 129 | if userInput != "none": inputCycle = False 130 | 131 | 132 | if userInput == 'hit': 133 | hand['human'].append(deck.pop(0)) 134 | if self.handCount(hand['human']) > 21: 135 | playHuman = False 136 | bustedHuman = True 137 | elif userInput == 'stand': 138 | playHuman = False 139 | 140 | playComputer = True 141 | bustedComputer = False 142 | 143 | while not bustedHuman and playComputer: 144 | 145 | if self.handCount(hand['computer']) < 17: 146 | hand['computer'].append(deck.pop(0)) 147 | else: 148 | playComputer = False 149 | 150 | if self.handCount(hand['computer']) > 21: 151 | playComputer = False 152 | bustedComputer = True 153 | 154 | print("pc : ", self.handCount(hand['computer']), "player : ", self.handCount(hand['human'])) 155 | 156 | if self.handCount(hand['human']) == 21: 157 | 158 | """ 159 | blackjack 160 | """ 161 | 162 | color = discord.Color.from_rgb(102, 187, 106) 163 | pcBustedEmbed = discord.Embed(description=f"Result: blackjack! {str(self.currency_symbol)} +{'{:,}'.format(int(bet*1.5))}", color=color) 164 | pcBustedEmbed.set_author(name=username, icon_url=user_pfp) 165 | pcBustedEmbed.add_field(name="**Your hand**", value=f"X X\nValue {self.handCount(hand['human'])}", inline=True) 166 | pcBustedEmbed.add_field(name="**Dealer shows**", value=f"X X\nValue {self.handCount(hand['computer'])}", inline=True) 167 | pcBustedEmbed.set_footer(text="Cards remaining: 999") 168 | await sentFirstEmbed.edit(embed=pcBustedEmbed) 169 | 170 | return "blackjack" 171 | 172 | elif bustedHuman: 173 | 174 | """ 175 | player busted 176 | """ 177 | 178 | color = discord.Color.from_rgb(239, 83, 80) 179 | playerBustEmbed = discord.Embed(description=f"Result: Bust {str(self.currency_symbol)} -{'{:,}'.format(int(bet))}", color=color) 180 | playerBustEmbed.set_author(name=username, icon_url=user_pfp) 181 | playerBustEmbed.add_field(name="**Your hand**", value=f"X X\nValue {self.handCount(hand['human'])}", inline=True) 182 | playerBustEmbed.add_field(name="**Dealer shows**", value=f"{str(hand['computer'][-1])}\nValue ?", inline=True) 183 | playerBustEmbed.set_footer(text="\r") 184 | await sentFirstEmbed.edit(embed=playerBustEmbed) 185 | 186 | return "loss" 187 | 188 | elif bustedComputer: 189 | 190 | """ 191 | dealer bust 192 | """ 193 | 194 | color = discord.Color.from_rgb(102, 187, 106) 195 | pcBustedEmbed = discord.Embed(description=f"Result: Dealer Bust {str(self.currency_symbol)} +{'{:,}'.format(int(bet))}", color=color) 196 | pcBustedEmbed.set_author(name=username, icon_url=user_pfp) 197 | pcBustedEmbed.add_field(name="**Your hand**", value=f"X X\nValue {self.handCount(hand['human'])}", inline=True) 198 | pcBustedEmbed.add_field(name="**Dealer shows**", value=f"X X\nValue {self.handCount(hand['computer'])}", inline=True) 199 | pcBustedEmbed.set_footer(text="Cards remaining: 999") 200 | await sentFirstEmbed.edit(embed=pcBustedEmbed) 201 | 202 | return "win" 203 | 204 | elif self.handCount(hand['human']) > self.handCount(hand['computer']): 205 | 206 | """ 207 | player win 208 | """ 209 | 210 | color = discord.Color.from_rgb(102, 187, 106) 211 | playerWinEmbed = discord.Embed(description=f"Result: Win {str(self.currency_symbol)} +{'{:,}'.format(int(bet))}", color=color) 212 | playerWinEmbed.set_author(name=username, icon_url=user_pfp) 213 | playerWinEmbed.add_field(name="**Your hand**", value=f"X X\nValue {self.handCount(hand['human'])}", inline=True) 214 | playerWinEmbed.add_field(name="**Dealer shows**", value=f"X X\nValue {self.handCount(hand['computer'])}", inline=True) 215 | playerWinEmbed.set_footer(text="Cards remaining: 999") 216 | await sentFirstEmbed.edit(embed=playerWinEmbed) 217 | 218 | return "win" 219 | 220 | elif self.handCount(hand['human']) == self.handCount(hand['computer']): 221 | 222 | """ 223 | bust 224 | """ 225 | 226 | color = discord.Color.from_rgb(255, 141, 1) 227 | playerWinEmbed = discord.Embed(description=f"Result: Push, money back", color=color) 228 | playerWinEmbed.set_author(name=username, icon_url=user_pfp) 229 | playerWinEmbed.add_field(name="**Your hand**", value=f"X X\nValue {self.handCount(hand['human'])}", inline=True) 230 | playerWinEmbed.add_field(name="**Dealer shows**", value=f"X X\nValue {self.handCount(hand['computer'])}", inline=True) 231 | playerWinEmbed.set_footer(text="Cards remaining: 999") 232 | await sentFirstEmbed.edit(embed=playerWinEmbed) 233 | 234 | return "bust" 235 | 236 | else: 237 | 238 | """ 239 | dealer win 240 | """ 241 | 242 | color = discord.Color.from_rgb(239, 83, 80) 243 | pcWinEmbed = discord.Embed(description=f"Result: Loss {str(self.currency_symbol)} -{'{:,}'.format(int(bet))}", color=color) 244 | pcWinEmbed.set_author(name=username, icon_url=user_pfp) 245 | pcWinEmbed.add_field(name="**Your hand**", value=f"X X\nValue {self.handCount(hand['human'])}", inline=True) 246 | pcWinEmbed.add_field(name="**Dealer Hand**", value=f"X X\nValue {self.handCount(hand['computer'])}", inline=True) 247 | pcWinEmbed.set_footer(text="\r") 248 | await sentFirstEmbed.edit(embed=pcWinEmbed) 249 | 250 | return "loss" 251 | 252 | # finished blackjack ! back to handling database 253 | return 254 | -------------------------------------------------------------------------------- /src/game_libs/roulette/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | START OF ROOULETTE 3 | ROULETTE GAME SLOTS found on https://github.com/ntaliceo/roulette-simulator, 4 | rest is done here 5 | """ 6 | 7 | import random, discord, time, asyncio 8 | 9 | 10 | # what will be called to play the game 11 | class roulette_discord_implementation: 12 | def __init__(self, bot, channel, currency_emoji): 13 | self.bot = bot 14 | self.channel = channel 15 | self.currency_symbol = currency_emoji 16 | # note on 12.10.23: im gonna remove <'00': 'green',> to make it a european roulette game 17 | self.slots = {'0': 'green', '1': 'red', '2': 'black', 18 | '3': 'red', '4': 'black', '5': 'red', '6': 'black', '7': 'red', 19 | '8': 'black', '9': 'red', '10': 'black', '11': 'red', 20 | '12': 'black', '13': 'red', '14': 'black', '15': 'red', 21 | '16': 'black', '17': 'red', '18': 'black', '19': 'red', 22 | '20': 'black', '21': 'red', '22': 'black', '23': 'red', 23 | '24': 'black', '25': 'red', '26': 'black', '27': 'red', 24 | '28': 'black', '29': 'red', '30': 'black', '31': 'red', 25 | '32': 'black', '33': 'red', '34': 'black', '35': 'red', 26 | '36': 'black'} 27 | """ 28 | 29 | not used but may be, if adding that multiple player can play the same roulette game at once 30 | 31 | async def get_user_input(self, message): 32 | # we want an answer from the guy who wants to give an answer 33 | answer = await self.bot.wait_for("message", check=lambda response: response.author == message.author) 34 | answer = answer.content 35 | # clean input 36 | answer = answer.lower().strip() 37 | # we only want hit or stand, nothing else, and still wait after that tho 38 | if answer not in ["hit", "stand"]: 39 | return "none" 40 | 41 | return answer 42 | """ 43 | 44 | async def play(self, bot, channel, username, user_pfp, bet, space, mention): 45 | self.bot = bot 46 | 47 | # get space type 48 | spaceType = "string" 49 | try: 50 | space = int(space) 51 | spaceType = "int" 52 | except: 53 | pass 54 | space = str(space).lower().strip() 55 | 56 | color = discord.Color.from_rgb(3, 169, 244) 57 | embed = discord.Embed(description=f"You have placed a bet of {str(self.currency_symbol)} {bet} on `{space}`.", color=color) 58 | embed.set_author(name=username, icon_url=user_pfp) 59 | embed.set_footer(text="Spinning ! ... time remaining: 5 seconds") 60 | await channel.send(embed=embed) 61 | 62 | # wait the 10 seconds 63 | # await asyncio.sleep(10) # made problems with json, couldnt change while roulette was running. 64 | time.sleep(5) 65 | 66 | win = lose = multiplicator = None 67 | 68 | if space in ["odd", "even", "black", "red"]: 69 | multiplicator = 2 70 | else: 71 | multiplicator = 35 72 | 73 | result = random.choice(list(self.slots.keys())) 74 | # print(self.slots[result], result) 75 | # print(type(result)) 76 | result_prompt = f"The ball landed on: **{self.slots[result]} {result}**!\n\n" 77 | 78 | if space == "black": 79 | win = 1 if self.slots[result] == "black" else 0 80 | 81 | elif space == "red": 82 | win = 1 if self.slots[result] == "red" else 0 83 | 84 | elif space == "even": 85 | result = int(result) 86 | win = 1 if (result % 2) == 0 else 0 87 | 88 | elif space == "odd": 89 | result = int(result) 90 | win = 1 if (result % 2) != 0 else 0 91 | 92 | elif spaceType == "int": 93 | win = 1 if space == result else 0 94 | 95 | else: 96 | # shouldnt happen 97 | print("error") 98 | # print("here") 99 | if win: 100 | result_prompt += f"🎉 **Winner:** 🎉\n{mention} won {str(self.currency_symbol)} {bet*multiplicator}" 101 | else: 102 | result_prompt += "**No Winner :(**" 103 | 104 | # inform user 105 | await channel.send(result_prompt) 106 | 107 | return win, multiplicator 108 | 109 | -------------------------------------------------------------------------------- /src/main.py: -------------------------------------------------------------------------------- 1 | 2 | # --------- Info and general informations ----------- 3 | 4 | """ 5 | INFO 6 | Official Repo: https://github.com/NoNameSpecified/UnbelievaBoat-Python-Bot 7 | 8 | This is a discord bot written in python, designed to copy some of Unbelievaboat's functions, 9 | but add custom stuff to it (e.g no balance limit, automatic balance increase etc) 10 | 11 | The Discord things are from the discord API (import discord) 12 | 13 | the databses are stored in database/ and handled by database/__init__.py 14 | that name is chosen to make it something easily importable 15 | 16 | some of these functions and methods are based on another Bot i made, https://github.com/NoNameSpecified/selenor 17 | """ 18 | 19 | # --------- BOT CODE BELOW ----------- 20 | 21 | 22 | 23 | """ 24 | 25 | // INIT 26 | 27 | """ 28 | 29 | # imports 30 | import discord 31 | import random 32 | from discord.ext.commands import Bot 33 | # custom database handler 34 | import database 35 | from time import sleep 36 | # check img url 37 | import requests, asyncio 38 | 39 | 40 | # init discord stuff and json handling 41 | BOT_PREFIX = ("+") # tupple in case we'd need multiple 42 | token = "putyourtokenhere" # add your own token 43 | # emojis 44 | emoji_worked = "✅" 45 | emoji_error = "❌" 46 | discord_error_rgb_code = discord.Color.from_rgb(239, 83, 80) 47 | intents = discord.Intents.all() 48 | client = Bot(command_prefix=BOT_PREFIX, intents=intents) # init bot 49 | db_handler = database.pythonboat_database_handler(client) # ("database.json") 50 | 51 | 52 | """ 53 | 54 | // GLOBAL FUNCTIONS 55 | 56 | """ 57 | 58 | async def get_user_input(message, default_spell=True): 59 | print("Awaiting User Entry") 60 | # we want an answer from the guy who wants to give an answer 61 | answer = await client.wait_for("message", check=lambda response: response.author == message.author and response.channel == message.channel) 62 | answer = answer.content 63 | # clean input 64 | if default_spell: 65 | answer = answer.lower().strip() 66 | 67 | return answer 68 | 69 | async def get_user_id(param): 70 | reception_user_beta = str(param[1]) # the mention in channel gives us <@!USERID> OR <@USERIRD> 71 | reception_user = "" 72 | for i in range(len(reception_user_beta)): 73 | try: 74 | reception_user += str(int(reception_user_beta[i])) 75 | except: 76 | pass 77 | return reception_user 78 | 79 | async def get_role_id_multiple(user_input): 80 | roles = user_input.split(" ") # so we get a list 81 | roles_clean = [] 82 | 83 | for i in range(len(roles)): 84 | current_role = roles[i] 85 | new_current_role = "" 86 | for i in range(len(current_role)): 87 | try: 88 | new_current_role += str(int(current_role[i])) 89 | except: 90 | pass 91 | roles_clean.append(new_current_role) 92 | return roles_clean 93 | 94 | async def get_role_id_single(parameter): 95 | role_beta = str(parameter) # see another instance where i use this to see why 96 | role_clean = "" 97 | for i in range(len(role_beta)): 98 | try: 99 | role_clean += str(int(role_beta[i])) 100 | except: 101 | pass 102 | return role_clean 103 | 104 | async def send_embed(title, description, channel, color="default"): 105 | # some default colors 106 | colors = [0xe03ca5, 0xdd7b28, 0x60c842, 0x8ae1c2, 0x008c5a, 0xc5bcc5] 107 | if color == "default": color = 0xe03ca5 108 | # create the embed 109 | embed = discord.Embed(title=title, description=description, color=color) 110 | await channel.send(embed=embed) 111 | return 112 | 113 | 114 | async def send_error(channel): 115 | embed = discord.Embed(title="Error.", description="Internal Error, call admin.", color=0xff0000) 116 | await channel.send(embed=embed) 117 | return 118 | 119 | 120 | # ~~~ set custom status ~~~ 121 | @client.event 122 | async def on_ready(): 123 | activity = discord.Game(name=f"My default prefix is <{BOT_PREFIX}>") 124 | await client.change_presence(status=discord.Status.online, activity=activity) 125 | # log_channel = 807057317396217947 # in your server, select a channel you want log info to be sent to 126 | # rightclick and copy id. put the id here. it should look like this : 807057317396217947 127 | """ 128 | NEED LOG CHANNEL ID 129 | """ 130 | # channel = client.get_channel(log_channel) 131 | # await channel.send("running") 132 | 133 | 134 | # check json, putting it here because has to be in a async function 135 | check_status = await db_handler.check_json() 136 | 137 | if check_status == "error": 138 | # channel = client.get_channel(log_channel) 139 | color = discord_error_rgb_code 140 | embed = discord.Embed(description=f"Critical error. JSON file is corrupted or has missing variables.\n\n" 141 | # f"`Error` code : {error_info}`\n" # -- Possibly to add 142 | f" Please contact an admin or delete the JSON database, but do a backup before -\n" 143 | f"this will result in re-creating the default config but will also **delete all user data**\n\n", color=color) 144 | embed.set_author(name="UnbelievaBoat-Python Bot", icon_url="https://blog.learningtree.com/wp-content/uploads/2017/01/error-handling.jpg") 145 | embed.set_footer(text="tip: default config at https://github.com/NoNameSpecified/UnbelievaBoat-Python-Bot") 146 | # await channel.send(embed=embed) 147 | quit() 148 | 149 | db_handler.get_currency_symbol() 150 | 151 | """ 152 | 153 | USER-BOT INTERACTION 154 | 155 | """ 156 | not_done = False 157 | @client.event 158 | async def on_message(message): 159 | """ 160 | start general variable definition 161 | """ 162 | global not_done 163 | # check if message is for our bot 164 | if not ( message.content.startswith(BOT_PREFIX) ) : return 0; 165 | 166 | # prefix checked, we can continue 167 | usedPrefix = message.content[0] # in case we would add more prefixes later 168 | # in selenor bot : check for case sensitive or not c.s. commands, not needed for this bot, 169 | # make it a clean input 170 | command = message.content.split(usedPrefix)[1].lower().split(" ") 171 | 172 | # stop if not meant for bot. (like just a "?") 173 | if command[0] in ["", " "]: return 0; 174 | 175 | """ 176 | basically, if the command is : 177 | +give money blabla 178 | we take what is after the prefix and before everything else, to just get the command 179 | in this case : "give" 180 | edit : for now we just splitted it, pure command will be taken with command = command[0] 181 | this is to redirect the command to further handling 182 | """ 183 | # print(command) # for testing purposes 184 | 185 | param_index = 1 186 | param = ["none", "none", "none", "none"] 187 | command_updated = [] 188 | # lets say our command says "remove-item " 189 | 190 | try: 191 | for test_cmd in range(len(command)): 192 | if command[test_cmd].startswith('"') or command[test_cmd].startswith("'"): 193 | new_slide = "" 194 | temp_cmd = test_cmd 195 | while not(command[temp_cmd].endswith('"') or command[temp_cmd].endswith("'")): 196 | new_slide += command[temp_cmd] + " " 197 | temp_cmd += 1 198 | new_slide += command[temp_cmd] 199 | command_updated.append(new_slide[1:len(new_slide)-1]) 200 | break 201 | elif command[test_cmd] in [" ", ""]: 202 | continue 203 | else: 204 | command_updated.append(command[test_cmd]) 205 | except: 206 | await message.channel.send("Error. You maybe opened a single/doublequote or a < and didnt close it") 207 | command = command_updated 208 | # print(command) 209 | for param_index in range(len(command)): 210 | param[param_index] = command[param_index] 211 | print(f"Command called with parameters : {param}") 212 | # for use of parameters later on, will have to start at 0, not 1 213 | 214 | # ~~~~ GET DISCORD VARIABLES for use later on 215 | # to directly answer in the channel the user called in 216 | channel = message.channel 217 | server = message.guild 218 | user = message.author.id 219 | user_mention = message.author.mention 220 | user_pfp = message.author.display_avatar.url 221 | username = str(message.author) 222 | nickname = str(message.author.display_name) 223 | user_roles = [randomvar.id for randomvar in message.author.roles] 224 | 225 | # some stuff will be only for staff, which will be recognizable by the botmaster role 226 | staff_request = 0 227 | for role_to_check in message.author.roles: 228 | if role_to_check.name == "botmaster": staff_request = 1 229 | print("staff status : ", staff_request) 230 | command = command[0] 231 | 232 | # 233 | 234 | """ 235 | START PROCESSING COMMANDS 236 | """ 237 | 238 | """ 239 | 240 | possible improvements : everything in int, not float 241 | all displayed numbers with "," as thousands operator 242 | people can enter amounts with thousands operator 243 | """ 244 | 245 | """ 246 | REGULAR COMMANDS (not staff only) 247 | """ 248 | # list of commands # their aliases, to make the help section easier 249 | all_reg_commands_aliases = { 250 | "blackjack" : "bj", 251 | "roulette" : "", 252 | "slut": "", 253 | "crime": "", 254 | "work": "", 255 | "rob": "steal", 256 | "balance": "bal", 257 | "deposit": "dep", 258 | "withdraw": "with", 259 | "give": "pay", 260 | "leaderboard": "lb", 261 | "help": "info", 262 | "module": "moduleinfo", 263 | "use": "use-item" 264 | } 265 | all_reg_commands = list(all_reg_commands_aliases.keys()) 266 | 267 | # -------------- 268 | # BLACKJACK GAME 269 | # -------------- 270 | 271 | if command in [ "blackjack", all_reg_commands_aliases["blackjack"] ]: 272 | if "none" in param[1] or param[2] != "none": # only bj ; nothing more than that 1 parameter 273 | color = discord_error_rgb_code 274 | embed = discord.Embed(description=f"{emoji_error} Too few arguments given.\n\nUsage:\n`blackjack `", color=color) 275 | embed.set_author(name=username, icon_url=user_pfp) 276 | await channel.send(embed=embed) 277 | return 278 | 279 | bet = param[1] 280 | # either all or an amount, not some random string 281 | if bet != "all": 282 | try: 283 | # they can use the thousands separator comma 284 | newAmount = [] 285 | for char in bet: 286 | if char != ",": 287 | newAmount.append(char) 288 | bet = "".join(newAmount) 289 | bet = int(bet) 290 | if bet < 100: 291 | color = discord_error_rgb_code 292 | embed = discord.Embed(description=f"{emoji_error} Invalid `` argument given. Bet must be at least 100.\n", color=color) 293 | embed.set_author(name=username, icon_url=user_pfp) 294 | await channel.send(embed=embed) 295 | return 296 | except: 297 | color = discord_error_rgb_code 298 | embed = discord.Embed(description=f"{emoji_error} Invalid `` argument given.\n\nUsage:\n`roulette `", color=color) 299 | embed.set_author(name=username, icon_url=user_pfp) 300 | await channel.send(embed=embed) 301 | return 302 | bet = str(bet) 303 | 304 | 305 | try: 306 | # gotta check if enough money, if bet enough, etc etc then do the actual game 307 | status, bj_return = await db_handler.blackjack(user, bet, client, channel, username, user_pfp, message) 308 | 309 | if status == "error": 310 | color = discord_error_rgb_code 311 | embed = discord.Embed(description=f"{bj_return}", color=color) 312 | embed.set_author(name=username, icon_url=user_pfp) 313 | await channel.send(embed=embed) 314 | return 315 | except Exception as e: 316 | print(e) 317 | await send_error(channel) 318 | # "success" case where code doesnt fail is answering client directly in handler 319 | # same for all other games 320 | return 321 | 322 | # -------------- 323 | # ROULETTE GAME 324 | # -------------- 325 | 326 | # ATTENTION : for now roulette is only playable by ONE person, multiple can't play at once 327 | 328 | elif command in [ "roulette", all_reg_commands_aliases["roulette"] ]: # no alias 329 | if "none" in param[1] or "none" in param[2]: # we need 2 parameters 330 | color = discord_error_rgb_code 331 | embed = discord.Embed(description=f"{emoji_error} Too few arguments given.\n\nUsage:\n`roulette `", color=color) 332 | embed.set_author(name=username, icon_url=user_pfp) 333 | await channel.send(embed=embed) 334 | return 335 | 336 | bet = param[1] 337 | # either all or an amount, not some random string 338 | if bet != "all": 339 | try: 340 | # they can use the thousands separator comma 341 | newAmount = [] 342 | for char in bet: 343 | if char != ",": 344 | newAmount.append(char) 345 | bet = "".join(newAmount) 346 | bet = int(bet) 347 | if bet < 100: 348 | color = discord_error_rgb_code 349 | embed = discord.Embed(description=f"{emoji_error} Invalid `` argument given. Bet must be at least 100.\n", color=color) 350 | embed.set_author(name=username, icon_url=user_pfp) 351 | await channel.send(embed=embed) 352 | return 353 | except: 354 | color = discord_error_rgb_code 355 | embed = discord.Embed(description=f"{emoji_error} Invalid `` argument given.\n\nUsage:\n`roulette `", color=color) 356 | embed.set_author(name=username, icon_url=user_pfp) 357 | await channel.send(embed=embed) 358 | return 359 | bet = str(bet) 360 | 361 | # space must be in second, and a valid space 362 | space = str(param[2]) 363 | if space not in ["odd", "even", "black", "red"]: 364 | fail = 0 365 | try: 366 | space = int(space) 367 | if not(space >= 0 and space <= 36): 368 | fail = 1 369 | except Exception as e: 370 | print(e) 371 | fail = 1 372 | if fail == 1: 373 | color = discord_error_rgb_code 374 | embed = discord.Embed(description=f"{emoji_error} Invalid `` argument given.\n\nUsage:\n`roulette `", color=color) 375 | embed.set_author(name=username, icon_url=user_pfp) 376 | await channel.send(embed=embed) 377 | return 378 | 379 | # convert to str, even if number. will be checked in the game itself later 380 | space = str(space) 381 | 382 | try: 383 | not_done = True 384 | # gotta check if enough money, if bet enough, etc etc then do the actual game 385 | status, roulette_return = await db_handler.roulette(user, bet, space, client, channel, username, user_pfp, user_mention) 386 | 387 | if status == "error": 388 | color = discord_error_rgb_code 389 | embed = discord.Embed(description=f"{roulette_return}", color=color) 390 | embed.set_author(name=username, icon_url=user_pfp) 391 | await channel.send(embed=embed) 392 | return 393 | except Exception as e: 394 | print(e) 395 | await send_error(channel) 396 | # print("finished func") 397 | not_done = False 398 | return 399 | 400 | # -------------- 401 | # SLUT 402 | # -------------- 403 | 404 | elif command in ["slut", all_reg_commands_aliases["slut"]]: # no alias 405 | try: 406 | status, slut_return = await db_handler.slut(user, channel, username, user_pfp) 407 | 408 | if status == "error": 409 | color = discord_error_rgb_code 410 | embed = discord.Embed(description=f"{slut_return}", color=color) 411 | embed.set_author(name=username, icon_url=user_pfp) 412 | await channel.send(embed=embed) 413 | return 414 | except Exception as e: 415 | print(e) 416 | await send_error(channel) 417 | 418 | # -------------- 419 | # CRIME 420 | # -------------- 421 | 422 | elif command in ["crime", all_reg_commands_aliases["crime"]]: # no alias 423 | try: 424 | status, crime_return = await db_handler.crime(user, channel, username, user_pfp) 425 | 426 | if status == "error": 427 | color = discord_error_rgb_code 428 | embed = discord.Embed(description=f"{crime_return}", color=color) 429 | embed.set_author(name=username, icon_url=user_pfp) 430 | await channel.send(embed=embed) 431 | return 432 | except Exception as e: 433 | print(e) 434 | await send_error(channel) 435 | 436 | # -------------- 437 | # WORK 438 | # -------------- 439 | 440 | elif command in ["work", all_reg_commands_aliases["work"]]: # no alias 441 | try: 442 | status, work_return = await db_handler.work(user, channel, username, user_pfp) 443 | 444 | if status == "error": 445 | color = discord_error_rgb_code 446 | embed = discord.Embed(description=f"{work_return}", color=color) 447 | embed.set_author(name=username, icon_url=user_pfp) 448 | await channel.send(embed=embed) 449 | return 450 | 451 | except Exception as e: 452 | print(e) 453 | await send_error(channel) 454 | 455 | 456 | 457 | # -------------- 458 | # ROB 459 | # -------------- 460 | 461 | elif command in ["rob", all_reg_commands_aliases["rob"]]: # no alias 462 | # you gotta rob someone 463 | if "none" in param[1] or param[2] != "none": # we only one param 464 | color = discord_error_rgb_code 465 | embed = discord.Embed(description=f"{emoji_error} Too few arguments given.\n\nUsage:\n`rob `", color=color) 466 | embed.set_author(name=username, icon_url=user_pfp) 467 | await channel.send(embed=embed) 468 | return 469 | 470 | user_to_rob = await get_user_id(param) 471 | 472 | try: 473 | status, rob_return = await db_handler.rob(user, channel, username, user_pfp, user_to_rob) 474 | 475 | if status == "error": 476 | color = discord_error_rgb_code 477 | embed = discord.Embed(description=f"{rob_return}", color=color) 478 | embed.set_author(name=username, icon_url=user_pfp) 479 | await channel.send(embed=embed) 480 | return 481 | except Exception as e: 482 | print(e) 483 | await send_error(channel) 484 | 485 | # -------------- 486 | # BALANCE 487 | # -------------- 488 | 489 | elif command in ["balance", all_reg_commands_aliases["balance"]]: 490 | # you can either check your own balance or someone else's bal 491 | if "none" in param[1]: 492 | # tell handler to check bal of this user 493 | userbal_to_check = user 494 | username_to_check = username 495 | userpfp_to_check = user_pfp 496 | # only one user to check, so only 1 param, if 2 -> error 497 | elif param[1] != "none" and param[2] != "none": 498 | color = discord_error_rgb_code 499 | embed = discord.Embed(description=f"{emoji_error} Invalid `[user]` argument given.\n\nUsage:\n`balance `", color=color) 500 | embed.set_author(name=username, icon_url=user_pfp) 501 | await channel.send(embed=embed) 502 | return 503 | # else we want the balance of someone else 504 | else: 505 | userbal_to_check = await get_user_id(param) 506 | try: 507 | user_fetch = client.get_user(int(userbal_to_check)) 508 | print("hello ?") 509 | username_to_check = user_fetch 510 | userpfp_to_check = user_fetch.avatar 511 | except: 512 | # we didnt find him 513 | color = discord_error_rgb_code 514 | embed = discord.Embed(description=f"{emoji_error} Invalid `[user]` argument given.\n\nUsage:\n`balance `", color=color) 515 | embed.set_author(name=username, icon_url=user_pfp) 516 | await channel.send(embed=embed) 517 | return 518 | 519 | # go through the handler 520 | try: 521 | await db_handler.balance(user, channel, userbal_to_check, username_to_check, userpfp_to_check, not_done) 522 | except Exception as e: 523 | print(e) 524 | await send_error(channel) 525 | 526 | # -------------- 527 | # DEP 528 | # -------------- 529 | 530 | elif command in ["deposit", all_reg_commands_aliases["deposit"]]: 531 | if "none" in param[1] or param[2] != "none": # we need 1 and only 1 parameter 532 | color = discord_error_rgb_code 533 | embed = discord.Embed(description=f"{emoji_error} Too few arguments given.\n\nUsage:\n`deposit `", color=color) 534 | embed.set_author(name=username, icon_url=user_pfp) 535 | await channel.send(embed=embed) 536 | return 537 | 538 | amount = param[1] 539 | # either all or an amount, not some random string 540 | if amount != "all": 541 | try: 542 | # they can use the thousands separator comma 543 | newAmount = [] 544 | for char in amount: 545 | if char != ",": 546 | newAmount.append(char) 547 | amount = "".join(newAmount) 548 | amount = int(amount) 549 | if amount < 1: 550 | color = discord_error_rgb_code 551 | embed = discord.Embed(description=f"{emoji_error} Invalid `` argument given.\n\nUsage:\n`deposit `", color=color) 552 | embed.set_author(name=username, icon_url=user_pfp) 553 | await channel.send(embed=embed) 554 | return 555 | except: 556 | color = discord_error_rgb_code 557 | embed = discord.Embed(description=f"{emoji_error} Invalid `` argument given.\n\nUsage:\n`deposit `", color=color) 558 | embed.set_author(name=username, icon_url=user_pfp) 559 | await channel.send(embed=embed) 560 | return 561 | 562 | try: 563 | amount = str(amount) 564 | status, dep_return = await db_handler.deposit(user, channel, username, user_pfp, amount) 565 | 566 | if status == "error": 567 | color = discord_error_rgb_code 568 | embed = discord.Embed(description=f"{dep_return}", color=color) 569 | embed.set_author(name=username, icon_url=user_pfp) 570 | await channel.send(embed=embed) 571 | return 572 | except Exception as e: 573 | print(e) 574 | await send_error(channel) 575 | 576 | # -------------- 577 | # WITH 578 | # -------------- 579 | 580 | elif command in ["withdraw", all_reg_commands_aliases["withdraw"]]: 581 | if "none" in param[1] or param[2] != "none": # we need 1 and only 1 parameter 582 | color = discord_error_rgb_code 583 | embed = discord.Embed(description=f"{emoji_error} Too few arguments given.\n\nUsage:\n`withdraw `", color=color) 584 | embed.set_author(name=username, icon_url=user_pfp) 585 | await channel.send(embed=embed) 586 | return 587 | 588 | amount = param[1] 589 | # either all or an amount, not some random string 590 | if amount != "all": 591 | try: 592 | # they can use the thousands separator comma 593 | newAmount = [] 594 | for char in amount: 595 | if char != ",": 596 | newAmount.append(char) 597 | amount = "".join(newAmount) 598 | amount = int(amount) 599 | if amount < 1: 600 | color = discord_error_rgb_code 601 | embed = discord.Embed(description=f"{emoji_error} Invalid `` argument given.\n\nUsage:\n`withdraw `", color=color) 602 | embed.set_author(name=username, icon_url=user_pfp) 603 | await channel.send(embed=embed) 604 | return 605 | except: 606 | color = discord_error_rgb_code 607 | embed = discord.Embed(description=f"{emoji_error} Invalid `` argument given.\n\nUsage:\n`withdraw `", color=color) 608 | embed.set_author(name=username, icon_url=user_pfp) 609 | await channel.send(embed=embed) 610 | return 611 | 612 | try: 613 | amount = str(amount) 614 | status, with_return = await db_handler.withdraw(user, channel, username, user_pfp, amount) 615 | 616 | if status == "error": 617 | color = discord_error_rgb_code 618 | embed = discord.Embed(description=f"{with_return}", color=color) 619 | embed.set_author(name=username, icon_url=user_pfp) 620 | await channel.send(embed=embed) 621 | return 622 | except Exception as e: 623 | print(e) 624 | await send_error(channel) 625 | 626 | # -------------- 627 | # GIVE 628 | # -------------- 629 | 630 | elif command in ["give", all_reg_commands_aliases["give"]]: 631 | if "none" in param[1] or "none" in param[2]: # we need 2 parameters 632 | color = discord_error_rgb_code 633 | embed = discord.Embed( 634 | description=f"{emoji_error} Too few arguments given.\n\nUsage:\n`give `\nInfo: for items use give-item!", 635 | color=color) 636 | embed.set_author(name=username, icon_url=user_pfp) 637 | await channel.send(embed=embed) 638 | return 639 | 640 | # we need to check validity of both parameters 641 | 642 | # CHECK 1 643 | 644 | reception_user = await get_user_id(param) 645 | 646 | try: 647 | user_fetch = client.get_user(int(reception_user)) 648 | print(user_fetch) 649 | reception_user_name = user_fetch 650 | 651 | if int(reception_user) == user: 652 | # cannot send money to yourself 653 | color = discord_error_rgb_code 654 | embed = discord.Embed(description=f"{emoji_error} You cannot trade money with yourself. That would be pointless.\n" 655 | f"(You may be looking for the `add-money` command.)", color=color) 656 | embed.set_author(name=username, icon_url=user_pfp) 657 | await channel.send(embed=embed) 658 | return 659 | 660 | except: 661 | # we didnt find him 662 | color = discord_error_rgb_code 663 | embed = discord.Embed(description=f"{emoji_error} Invalid `` argument given.\n\nUsage:" 664 | f"\n`give `", color=color) 665 | embed.set_author(name=username, icon_url=user_pfp) 666 | await channel.send(embed=embed) 667 | return 668 | 669 | # CHECK 2 670 | 671 | amount = param[2] 672 | # either all or an amount, not some random string 673 | if amount != "all": 674 | try: 675 | # they can use the thousands separator comma 676 | newAmount = [] 677 | for char in amount: 678 | if char != ",": 679 | newAmount.append(char) 680 | amount = "".join(newAmount) 681 | amount = int(amount) 682 | if amount < 1: 683 | color = discord_error_rgb_code 684 | embed = discord.Embed(description=f"{emoji_error} Invalid `` argument given.\n\nUsage:\n`give `", color=color) 685 | embed.set_author(name=username, icon_url=user_pfp) 686 | await channel.send(embed=embed) 687 | return 688 | except: 689 | color = discord_error_rgb_code 690 | embed = discord.Embed( 691 | description=f"{emoji_error} Invalid `` argument given.\n\nUsage:\n`give `", 692 | color=color) 693 | embed.set_author(name=username, icon_url=user_pfp) 694 | await channel.send(embed=embed) 695 | return 696 | 697 | # handler 698 | 699 | try: 700 | amount = str(amount) 701 | status, give_return = await db_handler.give(user, channel, username, user_pfp, reception_user, amount, reception_user_name) 702 | 703 | if status == "error": 704 | color = discord_error_rgb_code 705 | embed = discord.Embed(description=f"{give_return}", color=color) 706 | embed.set_author(name=username, icon_url=user_pfp) 707 | await channel.send(embed=embed) 708 | return 709 | except Exception as e: 710 | print(e) 711 | await send_error(channel) 712 | 713 | # -------------- 714 | # LEADERBOARD 715 | # -------------- 716 | 717 | elif command in ["leaderboard", all_reg_commands_aliases["leaderboard"]]: 718 | modes = ["-cash", "-bank", "-total"] 719 | page_number = 1 720 | mode_type = modes[2] 721 | server_name = server.name 722 | full_name = server_name # + mode_type 723 | 724 | # first, vanilla 725 | if "none" in param[1] and "none" in param[2]: 726 | # using default vars 727 | page_number = 1 728 | mode_type = modes[2] 729 | full_name += " Leaderboard" 730 | # one argument 731 | elif param[1] != "none" and "none" in param[2]: 732 | if param[1] in modes: 733 | mode_type = param[1] 734 | page_number = 1 735 | if mode_type == "-total": full_name += " Leaderboard" 736 | if mode_type == "-cash": full_name += " Cash Leaderboard" 737 | if mode_type == "-bank": full_name += " Bank Leaderboard" 738 | else: 739 | try: 740 | page_number = int(param[1]) 741 | mode_type = modes[2] 742 | full_name += " Leaderboard" 743 | except: 744 | color = discord_error_rgb_code 745 | embed = discord.Embed( 746 | description=f"{emoji_error} Invalid `[-cash | -bank | -total]` argument given.\n\nUsage:\n" 747 | f"`leaderboard [page] [-cash | -bank | -total]`", color=color) 748 | embed.set_author(name=username, icon_url=user_pfp) 749 | await channel.send(embed=embed) 750 | return 751 | # two arguments 752 | else: 753 | try: 754 | page_number = int(param[1]) 755 | mode_type = param[2] 756 | if mode_type == "-total": full_name += " Leaderboard" 757 | elif mode_type == "-cash": full_name += " Cash Leaderboard" 758 | elif mode_type == "-bank": full_name += " Bank Leaderboard" 759 | else: 760 | color = discord_error_rgb_code 761 | embed = discord.Embed( 762 | description=f"{emoji_error} Invalid `[-cash | -bank | -total]` argument given.\n\nUsage:\n" 763 | f"`leaderboard [page] [-cash | -bank | -total]`", color=color) 764 | embed.set_author(name=username, icon_url=user_pfp) 765 | await channel.send(embed=embed) 766 | return 767 | except: 768 | color = discord_error_rgb_code 769 | embed = discord.Embed( 770 | description=f"{emoji_error} Invalid `[-cash | -bank | -total]` argument given.\n\nUsage:\n" 771 | f"`leaderboard [page] [-cash | -bank | -total]`", color=color) 772 | embed.set_author(name=username, icon_url=user_pfp) 773 | await channel.send(embed=embed) 774 | return 775 | 776 | print(f"Looking for {full_name}, at page {page_number}, in mode {mode_type}") 777 | 778 | # handler 779 | 780 | try: 781 | status, lb_return = await db_handler.leaderboard(user, channel, username, full_name, page_number, mode_type, client) 782 | 783 | if status == "error": 784 | color = discord_error_rgb_code 785 | embed = discord.Embed(description=f"{lb_return}", color=color) 786 | embed.set_author(name=username, icon_url=user_pfp) 787 | await channel.send(embed=embed) 788 | return 789 | except Exception as e: 790 | print(e) 791 | await send_error(channel) 792 | 793 | # -------------- 794 | # HELP 795 | # -------------- 796 | 797 | elif command in ["help", all_reg_commands_aliases["help"]]: 798 | color = discord.Color.from_rgb(3, 169, 244) 799 | embed = discord.Embed(title=f"Help System", color=color) 800 | embed.add_field(name="stats", value=f"Usage: `stats`", inline=False) 801 | 802 | embed.add_field(name=all_reg_commands[0], value=f"Alias: {all_reg_commands_aliases[all_reg_commands[0]]} | " 803 | f"Usage: `blackjack `", inline=False) 804 | embed.add_field(name=all_reg_commands[1], value=f"Alias: {all_reg_commands_aliases[all_reg_commands[1]]} | " 805 | f"Usage: `roulette `", inline=False) 806 | embed.add_field(name=all_reg_commands[2], value=f"Alias: {all_reg_commands_aliases[all_reg_commands[2]]} | " 807 | f"Usage: `slut`", inline=False) 808 | embed.add_field(name=all_reg_commands[3], value=f"Alias: {all_reg_commands_aliases[all_reg_commands[3]]} | " 809 | f"Usage: `crime`", inline=False) 810 | embed.add_field(name=all_reg_commands[4], value=f"Alias: {all_reg_commands_aliases[all_reg_commands[4]]} | " 811 | f"Usage: `work`", inline=False) 812 | embed.add_field(name=all_reg_commands[5], value=f"Alias: {all_reg_commands_aliases[all_reg_commands[5]]} | " 813 | f"Usage: `rob`", inline=False) 814 | embed.add_field(name=all_reg_commands[6], value=f"Alias: {all_reg_commands_aliases[all_reg_commands[6]]} | " 815 | f"Usage: `balance`", inline=False) 816 | embed.add_field(name=all_reg_commands[7], value=f"Alias: {all_reg_commands_aliases[all_reg_commands[7]]} | " 817 | f"Usage: `deposit `", inline=False) 818 | embed.add_field(name=all_reg_commands[8], value=f"Alias: {all_reg_commands_aliases[all_reg_commands[8]]} | " 819 | f"Usage: `withdraw `", inline=False) 820 | embed.add_field(name=all_reg_commands[9], value=f"Alias: {all_reg_commands_aliases[all_reg_commands[9]]} | " 821 | f"Usage: `give `", inline=False) 822 | embed.add_field(name=all_reg_commands[10], value=f"Alias: {all_reg_commands_aliases[all_reg_commands[10]]} | " 823 | f"Usage: `leaderboard [page] [-cash | -bank | -total]`", inline=False) 824 | embed.add_field(name=all_reg_commands[11], value=f"Alias: {all_reg_commands_aliases[all_reg_commands[11]]} | " 825 | f"Usage: `help` - shows this", inline=False) 826 | embed.add_field(name=all_reg_commands[12], value=f"Alias: {all_reg_commands_aliases[all_reg_commands[12]]} | " 827 | f"Usage: `module `", inline=False) 828 | # edit stuff 829 | embed.set_footer(text="For more info, contact an admin or ") 830 | await channel.send(embed=embed) 831 | 832 | #### in 2 parts because one was too long 833 | 834 | embed = discord.Embed(title=f"Help System", color=color) 835 | embed.add_field(name="----------------------\n\nSTAFF ONLY", value=f"requires role", inline=False) 836 | embed.add_field(name="add-money", value=f"Usage: `add-money `", inline=False) 837 | embed.add_field(name="remove-money", value=f"Usage: `remove-money [cash/bank]`", inline=False) 838 | embed.add_field(name="remove-money-role", value=f"Usage: `remove-money-role `", inline=False) 839 | embed.add_field(name="change", value=f"Usage: `change `", inline=False) 840 | embed.add_field(name="change-currency", value=f"Usage: `change-currency `", inline=False) 841 | embed.add_field(name="set-income-reset", value=f"Usage: `set-income-reset `", inline=False) 842 | embed.add_field(name="remove-user-item", value=f"Usage: `remove-user-item `", inline=False) 843 | embed.add_field(name="spawn-item", value=f"Usage: `spawn-item [amount]`", inline=False) 844 | embed.add_field(name="clean-leaderboard", value=f"Usage: `clean-leaderboard` - remove gone users", inline=False) 845 | embed.add_field(name="----------------------\n\nITEM HANDLING", value=f"create and delete requires role", inline=False) 846 | embed.add_field(name="create-item", value=f"Usage: `create-item`", inline=False) 847 | embed.add_field(name="delete-item", value=f"Usage: `delete-item `", inline=False) 848 | embed.add_field(name="buy-item", value=f"Usage: `buy-item `", inline=False) 849 | embed.add_field(name="give-item", value=f"Usage: `give-item `", inline=False) 850 | embed.add_field(name="use", value=f"Usage: `use `", inline=False) 851 | embed.add_field(name="inventory", value=f"Usage: `inventory [page]`", inline=False) 852 | embed.add_field(name="user-inventory", value=f"Usage: `user-inventory [page]`", inline=False) 853 | embed.add_field(name="catalog", value=f"Usage: `catalog [item short name]`", inline=False) 854 | embed.add_field(name="----------------------\n\nINCOME ROLES", value=f"create, delete and update requires role", inline=False) 855 | embed.add_field(name="add-income-role", value=f"Usage: `add-income-role `", inline=False) 856 | embed.add_field(name="remove-income-role", value=f"Usage: `remove-income-role `", inline=False) 857 | embed.add_field(name="list-roles", value=f"Usage: `list-roles`", inline=False) 858 | embed.add_field(name="collect", value=f"Usage: `collect` | get your salary. If you choose to use update-income, please disable this command.", inline=False) 859 | embed.add_field(name="update-income", value=f"Usage: `update-income` | income works DAILY! automatically updates ALL INCOMES time elapsed * income.", inline=False) 860 | # edit stuff 861 | embed.set_footer(text="For more info, contact an admin or ") 862 | 863 | await channel.send(embed=embed) 864 | 865 | # -------------- 866 | # MODULE INFO 867 | # -------------- 868 | 869 | elif command in ["module", all_reg_commands_aliases["module"]]: 870 | if "none" in param[1] or param[2] != "none": # we need 1 and only 1 parameter 871 | color = discord_error_rgb_code 872 | embed = discord.Embed( 873 | description=f"{emoji_error} Too few arguments given.\n\nUsage:\n`module `", 874 | color=color) 875 | embed.set_author(name=username, icon_url=user_pfp) 876 | await channel.send(embed=embed) 877 | return 878 | 879 | module = param[1] 880 | 881 | # handler 882 | 883 | try: 884 | status, module_return = await db_handler.module(user, channel, module) 885 | 886 | if status == "error": 887 | color = discord_error_rgb_code 888 | embed = discord.Embed(description=f"{module_return}", color=color) 889 | embed.set_author(name=username, icon_url=user_pfp) 890 | await channel.send(embed=embed) 891 | return 892 | except Exception as e: 893 | print(e) 894 | await send_error(channel) 895 | 896 | """ 897 | STAFF COMMANDS 898 | """ 899 | 900 | # -------------- 901 | # ADD-MONEY 902 | # -------------- 903 | 904 | elif command == "add-money": 905 | if not staff_request: 906 | color = discord_error_rgb_code 907 | embed = discord.Embed(description=f"🔒 Requires botmaster role", color=color) 908 | embed.set_author(name=username, icon_url=user_pfp) 909 | await channel.send(embed=embed) 910 | return 911 | 912 | if "none" in param[1] or "none" in param[2]: # we need 2 parameters 913 | color = discord_error_rgb_code 914 | embed = discord.Embed(description=f"{emoji_error} Too few arguments given.\n\nUsage:\n`add-money `", color=color) 915 | embed.set_author(name=username, icon_url=user_pfp) 916 | await channel.send(embed=embed) 917 | return 918 | 919 | # we need to check validity of both parameters 920 | 921 | # CHECK 1 922 | 923 | reception_user = await get_user_id(param) 924 | try: 925 | user_fetch = client.get_user(int(reception_user)) 926 | print(user_fetch) 927 | reception_user_name = user_fetch 928 | 929 | except: 930 | # we didnt find him 931 | color = discord_error_rgb_code 932 | embed = discord.Embed(description=f"{emoji_error} Invalid `` argument given.\n\nUsage:" 933 | f"\n`add-money `", color=color) 934 | embed.set_author(name=username, icon_url=user_pfp) 935 | await channel.send(embed=embed) 936 | return 937 | 938 | # CHECK 2 939 | 940 | amount = param[2] 941 | try: 942 | # they can use the thousands separator comma 943 | newAmount = [] 944 | for char in amount: 945 | if char != ",": 946 | newAmount.append(char) 947 | amount = "".join(newAmount) 948 | amount = int(amount) 949 | if amount < 1: 950 | color = discord_error_rgb_code 951 | embed = discord.Embed( 952 | description=f"{emoji_error} Invalid `` argument given.\n\nUsage:\n`add-money `", 953 | color=color) 954 | embed.set_author(name=username, icon_url=user_pfp) 955 | await channel.send(embed=embed) 956 | return 957 | except: 958 | color = discord_error_rgb_code 959 | embed = discord.Embed(description=f"{emoji_error} Invalid `` argument given.\n\nUsage:\n`add-money `", color=color) 960 | embed.set_author(name=username, icon_url=user_pfp) 961 | await channel.send(embed=embed) 962 | return 963 | 964 | # handler 965 | 966 | try: 967 | amount = str(amount) 968 | status, add_money_return = await db_handler.add_money(user, channel, username, user_pfp, reception_user, amount, reception_user_name) 969 | 970 | if status == "error": 971 | color = discord_error_rgb_code 972 | embed = discord.Embed(description=f"{add_money_return}", color=color) 973 | embed.set_author(name=username, icon_url=user_pfp) 974 | await channel.send(embed=embed) 975 | return 976 | except Exception as e: 977 | print(e) 978 | await send_error(channel) 979 | 980 | # -------------- 981 | # REMOVE-MONEY 982 | # -------------- 983 | 984 | elif command == "remove-money": 985 | if not staff_request: 986 | color = discord_error_rgb_code 987 | embed = discord.Embed(description=f"🔒 Requires botmaster role", color=color) 988 | embed.set_author(name=username, icon_url=user_pfp) 989 | await channel.send(embed=embed) 990 | return 991 | 992 | if "none" in param[1] or "none" in param[2]: # we need 3 parameters 993 | color = discord_error_rgb_code 994 | embed = discord.Embed(description=f"{emoji_error} Too few arguments given.\n\nUsage:\n`remove-money [cash/bank]`", color=color) 995 | embed.set_author(name=username, icon_url=user_pfp) 996 | await channel.send(embed=embed) 997 | return 998 | 999 | # we need to check validity of both parameters 1000 | 1001 | # CHECK 1 1002 | 1003 | reception_user = await get_user_id(param) 1004 | 1005 | try: 1006 | user_fetch = client.get_user(int(reception_user)) 1007 | print(user_fetch) 1008 | reception_user_name = user_fetch 1009 | 1010 | except: 1011 | # we didnt find him 1012 | color = discord_error_rgb_code 1013 | embed = discord.Embed(description=f"{emoji_error} Invalid `` argument given.\n\nUsage:" 1014 | f"\n`remove-money [cash/bank]`", color=color) 1015 | embed.set_author(name=username, icon_url=user_pfp) 1016 | await channel.send(embed=embed) 1017 | return 1018 | 1019 | # CHECK 2 1020 | 1021 | amount = param[2] 1022 | try: 1023 | # they can use the thousands separator comma 1024 | newAmount = [] 1025 | for char in amount: 1026 | if char != ",": 1027 | newAmount.append(char) 1028 | amount = "".join(newAmount) 1029 | amount = int(amount) 1030 | if amount < 1: 1031 | color = discord_error_rgb_code 1032 | embed = discord.Embed( 1033 | description=f"{emoji_error} Invalid `` argument given.\n\nUsage:\n`remove-money [cash/bank]`", 1034 | color=color) 1035 | embed.set_author(name=username, icon_url=user_pfp) 1036 | await channel.send(embed=embed) 1037 | return 1038 | except: 1039 | color = discord_error_rgb_code 1040 | embed = discord.Embed(description=f"{emoji_error} Invalid `` argument given.\n\nUsage:\n`remove-money [cash/bank]`", color=color) 1041 | embed.set_author(name=username, icon_url=user_pfp) 1042 | await channel.send(embed=embed) 1043 | return 1044 | 1045 | # CHECK 3 1046 | mode = "bank" 1047 | if param[3] != "none": 1048 | if param[3] in ["cash", "bank"]: 1049 | mode = param[3] 1050 | else: 1051 | color = discord_error_rgb_code 1052 | embed = discord.Embed(description=f"{emoji_error} Invalid `[cash/bank]` argument given.\n\nUsage:" 1053 | f"\n`remove-money [cash/bank]`", color=color) 1054 | embed.set_author(name=username, icon_url=user_pfp) 1055 | await channel.send(embed=embed) 1056 | return 1057 | 1058 | # handler 1059 | 1060 | try: 1061 | amount = str(amount) 1062 | status, rm_money_return = await db_handler.remove_money(user, channel, username, user_pfp, reception_user, amount, reception_user_name, mode) 1063 | 1064 | if status == "error": 1065 | color = discord_error_rgb_code 1066 | embed = discord.Embed(description=f"{rm_money_return}", color=color) 1067 | embed.set_author(name=username, icon_url=user_pfp) 1068 | await channel.send(embed=embed) 1069 | return 1070 | except Exception as e: 1071 | print(e) 1072 | await send_error(channel) 1073 | 1074 | # -------------- 1075 | # EDIT VARS 1076 | # -------------- 1077 | 1078 | elif command in ["change", "edit"]: 1079 | if not staff_request: 1080 | color = discord_error_rgb_code 1081 | embed = discord.Embed(description=f"🔒 Requires botmaster role", color=color) 1082 | embed.set_author(name=username, icon_url=user_pfp) 1083 | await channel.send(embed=embed) 1084 | return 1085 | 1086 | if "none" in param[1] or "none" in param[2] or "none" in param[3]: # we need 3 parameters 1087 | color = discord_error_rgb_code 1088 | embed = discord.Embed(description=f"{emoji_error} Too few arguments given.\n\nUsage:\n`change `", color=color) 1089 | embed.set_author(name=username, icon_url=user_pfp) 1090 | await channel.send(embed=embed) 1091 | return 1092 | 1093 | # that would end up messing everything up 1094 | if param[2] == "name": 1095 | color = discord_error_rgb_code 1096 | embed = discord.Embed(description=f"{emoji_error} You cannot change module names.", color=color) 1097 | embed.set_author(name=username, icon_url=user_pfp) 1098 | await channel.send(embed=embed) 1099 | return 1100 | 1101 | # we need to check validity of new value parameter 1102 | # other checks will be done in the handler 1103 | 1104 | # CHECK 1105 | module_name = param[1] 1106 | variable_name = param[2] 1107 | new_value = param[3] 1108 | try: 1109 | new_value = int(new_value) 1110 | except: 1111 | color = discord_error_rgb_code 1112 | embed = discord.Embed(description=f"{emoji_error} Invalid `` argument given.\n\nUsage:\n`change `", color=color) 1113 | embed.set_author(name=username, icon_url=user_pfp) 1114 | await channel.send(embed=embed) 1115 | return 1116 | 1117 | # handler 1118 | 1119 | try: 1120 | new_value = str(new_value) 1121 | status, edit_return = await db_handler.edit_variables(user, channel, username, user_pfp, module_name, variable_name, new_value) 1122 | 1123 | if status == "error": 1124 | color = discord_error_rgb_code 1125 | embed = discord.Embed(description=f"{edit_return}", color=color) 1126 | embed.set_author(name=username, icon_url=user_pfp) 1127 | await channel.send(embed=embed) 1128 | return 1129 | except Exception as e: 1130 | print(e) 1131 | await send_error(channel) 1132 | 1133 | # --------------------------- 1134 | # CHANGE CURRENCY SYMBOL 1135 | # --------------------------- 1136 | 1137 | elif command in ["change-currency", "edit_currency"]: 1138 | if not staff_request: 1139 | color = discord_error_rgb_code 1140 | embed = discord.Embed(description=f"🔒 Requires botmaster role", color=color) 1141 | embed.set_author(name=username, icon_url=user_pfp) 1142 | await channel.send(embed=embed) 1143 | return 1144 | 1145 | if "none" in param[1]: # we need 1 parameters 1146 | color = discord_error_rgb_code 1147 | embed = discord.Embed(description=f"{emoji_error} Too few arguments given.\n\nUsage:\n`change-currency `", color=color) 1148 | embed.set_author(name=username, icon_url=user_pfp) 1149 | await channel.send(embed=embed) 1150 | return 1151 | 1152 | new_emoji_name = param[1] 1153 | 1154 | # handler 1155 | 1156 | try: 1157 | status, emoji_edit_return = await db_handler.change_currency_symbol(user, channel, username, user_pfp, new_emoji_name) 1158 | if status == "error": 1159 | color = discord_error_rgb_code 1160 | embed = discord.Embed(description=f"{emoji_edit_return}", color=color) 1161 | embed.set_author(name=username, icon_url=user_pfp) 1162 | await channel.send(embed=embed) 1163 | return 1164 | except Exception as e: 1165 | print(e) 1166 | await send_error(channel) 1167 | 1168 | # --------------------------- 1169 | # SET INCOME RESET 1170 | # --------------------------- 1171 | 1172 | elif command in ["set-income-reset", "change-income-reset"]: 1173 | if not staff_request: 1174 | color = discord_error_rgb_code 1175 | embed = discord.Embed(description=f"🔒 Requires botmaster role", color=color) 1176 | embed.set_author(name=username, icon_url=user_pfp) 1177 | await channel.send(embed=embed) 1178 | return 1179 | 1180 | if "none" in param[1]: # we need 1 parameter 1181 | color = discord_error_rgb_code 1182 | embed = discord.Embed( 1183 | description=f"{emoji_error} Too few arguments given.\n\nUsage: `set-income-reset `", 1184 | color=color) 1185 | embed.set_author(name=username, icon_url=user_pfp) 1186 | await channel.send(embed=embed) 1187 | return 1188 | 1189 | if param[1] not in ["true", "false"]: # and that param has to be true/false 1190 | color = discord_error_rgb_code 1191 | embed = discord.Embed( 1192 | description=f"{emoji_error} Too few arguments given.\n\nUsage: `set-income-reset `", 1193 | color=color) 1194 | embed.set_author(name=username, icon_url=user_pfp) 1195 | await channel.send(embed=embed) 1196 | return 1197 | 1198 | # ok so all checks done 1199 | new_income_reset = param[1] 1200 | 1201 | # handler 1202 | try: 1203 | status, new_income_reset_return = await db_handler.set_income_reset(user, channel, username, user_pfp, 1204 | new_income_reset) 1205 | if status == "error": 1206 | color = discord_error_rgb_code 1207 | embed = discord.Embed(description=f"{new_income_reset_return}", color=color) 1208 | embed.set_author(name=username, icon_url=user_pfp) 1209 | await channel.send(embed=embed) 1210 | return 1211 | except Exception as e: 1212 | print(e) 1213 | await send_error(channel) 1214 | 1215 | 1216 | """ 1217 | SPECIAL COMMANDS 1218 | """ 1219 | 1220 | # --------------------------- 1221 | # ITEM CREATION / Create item 1222 | # --------------------------- 1223 | 1224 | elif command in ["create-item", "new-item", "item-create"]: 1225 | if not staff_request: 1226 | color = discord_error_rgb_code 1227 | embed = discord.Embed(description=f"🔒 Requires botmaster role", color=color) 1228 | embed.set_author(name=username, icon_url=user_pfp) 1229 | await channel.send(embed=embed) 1230 | return 1231 | 1232 | currently_creating_item = True 1233 | checkpoints = 0 1234 | last_report = "" 1235 | color = discord.Color.from_rgb(3, 169, 244) 1236 | # send a first input which we will then edit 1237 | info_text = ":zero: What should the new item be called?\nThis name should be unique and no more than 200 characters.\nIt can contain symbols and multiple words." 1238 | first_embed = discord.Embed(title="Item Info", description="Display Name\n.", color=color) 1239 | first_embed.set_footer(text="Type cancel to quit") 1240 | await channel.send(info_text, embed=first_embed) 1241 | 1242 | while currently_creating_item: 1243 | # get input first 1244 | user_input = await get_user_input(message, default_spell=False) 1245 | print("at checkpoint ", checkpoints, "\ninput is ", user_input) 1246 | # check if user wants cancel 1247 | if user_input == "cancel": 1248 | await channel.send(f"{emoji_error} Cancelled command.") 1249 | return 1250 | 1251 | if checkpoints == 0: 1252 | # check 0: display name 1253 | if len(user_input) > 200: 1254 | await channel.send(f"{emoji_error} The maximum length for an items name is 200 characters. Please try again.") 1255 | continue 1256 | elif len(user_input) < 3: 1257 | await channel.send(f"{emoji_error} The minimum length for an items name is 3 characters. Please try again.") 1258 | continue 1259 | # good input 1260 | item_display_name = user_input 1261 | first_embed = discord.Embed(title="Item Info", color=color) 1262 | first_embed.add_field(name="Display Name", value=f"{item_display_name}") 1263 | first_embed.set_footer(text="Type cancel to quit") 1264 | next_info = ":one: Now we need a short name, which users will use when buying, giving etc. Only one word ! (you can use dashes and underscores)" 1265 | last_report = await channel.send(next_info, embed=first_embed) 1266 | checkpoints += 1 1267 | #item_name = await get_user_input(message) 1268 | #print(item_name) 1269 | trial = 0 1270 | 1271 | if checkpoints == 1: 1272 | trial +=1 1273 | item_name = await get_user_input(message) if trial == 1 else user_input 1274 | 1275 | # check 1: name 1276 | if len(item_name) > 10: 1277 | await channel.send(f"{emoji_error} The maximum length for an items short name is 10 characters. Please try again.") 1278 | continue 1279 | elif len(item_name) < 3: 1280 | await channel.send(f"{emoji_error} The minimum length for an items short name is 3 characters. Please try again.") 1281 | continue 1282 | elif " " in item_name.strip(): 1283 | print(f"-{item_name}- -{item_name.strip()}") 1284 | await channel.send(f"{emoji_error} short name has to be ONE word (dashes or underscores work).") 1285 | continue 1286 | # good input 1287 | first_embed.add_field(name="Short name", value=f"{item_name}") 1288 | first_embed.set_footer(text="Type cancel to quit") 1289 | next_info = ":two: How much should the item cost to purchase?" 1290 | await last_report.edit(content=next_info, embed=first_embed) 1291 | checkpoints += 1 1292 | 1293 | elif checkpoints == 2: 1294 | # check 2: cost 1295 | try: 1296 | cost = int(user_input) 1297 | if cost < 1: 1298 | await channel.send(f"{emoji_error} Invalid price given. Please try again or type cancel to exit.") 1299 | continue 1300 | except: 1301 | await channel.send(f"{emoji_error} Invalid price given. Please try again or type cancel to exit.") 1302 | continue 1303 | first_embed.add_field(name="Price", value=f"{cost}") 1304 | first_embed.set_footer(text="Type cancel to quit or skip to skip this option") 1305 | next_info = ":three: Please provide a description of the item.\nThis should be no more than 200 characters." 1306 | await last_report.edit(content=next_info, embed=first_embed) 1307 | checkpoints += 1 1308 | 1309 | elif checkpoints == 3: 1310 | # check 3: description 1311 | if len(user_input) > 200: 1312 | await channel.send(f"{emoji_error} The maximum length for an items description is 200 characters. Please try again.") 1313 | continue 1314 | if user_input.lower() == "skip": 1315 | description = "none" 1316 | else: 1317 | description = user_input 1318 | first_embed.add_field(name="Description", value=f"{description}", inline=False) 1319 | first_embed.set_footer(text="Type cancel to quit or skip to skip this option") 1320 | next_info = ":four: How long should this item stay in the store ? (integer, in days)\nMinimum duration is 1 day.\nIf no limit, just reply `skip`." 1321 | await last_report.edit(content=next_info, embed=first_embed) 1322 | checkpoints += 1 1323 | 1324 | elif checkpoints == 4: 1325 | # check 4: duration 1326 | try: 1327 | duration = int(user_input) 1328 | if duration < 1: 1329 | await channel.send(f"{emoji_error} Invalid time duration given. Please try again or type cancel to exit.") 1330 | continue 1331 | except: 1332 | if user_input.lower() == "skip": 1333 | #duration = "none" 1334 | duration = 99999 # the problem is that database.py always wants an int to calculate an expiration date. 1335 | # so ill just put it to 993 days for now, maybe ill add a real fix later 1336 | # edit: now changed to 99999 which should be enough, will show as "unlimited" 1337 | else: 1338 | await channel.send(f"{emoji_error} Invalid time duration given. Please try again or type cancel to exit.") 1339 | continue 1340 | if duration == 99999: 1341 | duration_str = "unlimited" 1342 | else: 1343 | duration_str = int(user_input) 1344 | first_embed.add_field(name="Time remaining", value=f"{duration} days left") 1345 | first_embed.set_footer(text="Type cancel to quit or skip to skip this option") 1346 | next_info = ":five: How much stock of this item will there be?\nIf unlimited, just reply `skip` or `infinity`." 1347 | await last_report.edit(content=next_info, embed=first_embed) 1348 | checkpoints += 1 1349 | 1350 | elif checkpoints == 5: 1351 | # check 5: stock 1352 | try: 1353 | stock = int(user_input) 1354 | if stock < 1: 1355 | await channel.send(f"{emoji_error} Invalid stock amount given. Please try again or type cancel to exit.") 1356 | continue 1357 | except: 1358 | if user_input.lower() == "skip" or user_input.lower() == "infinity": 1359 | stock = "unlimited" 1360 | else: 1361 | await channel.send(f"{emoji_error} Invalid stock amount given. Please try again or type cancel to exit.") 1362 | continue 1363 | 1364 | first_embed.add_field(name="Stock remaining", value=f"{stock}") 1365 | first_embed.set_footer(text="Type cancel to quit or skip to skip this option") 1366 | next_info = ":six: What is the MAX amount of this item per user that should be allowed ?\nIf none, just reply `skip`." 1367 | await last_report.edit(content=next_info, embed=first_embed) 1368 | checkpoints += 1 1369 | 1370 | elif checkpoints == 6: 1371 | # check 6: max amount of item 1372 | try: 1373 | max_amount = int(user_input) 1374 | if max_amount < 1: 1375 | await channel.send(f"{emoji_error} Invalid max amount given. Please try again or type cancel to exit.") 1376 | continue 1377 | except: 1378 | if user_input.lower() == "skip" or user_input.lower() == "infinity": 1379 | max_amount = "unlimited" 1380 | else: 1381 | await channel.send(f"{emoji_error} Invalid max amount given. Please try again or type cancel to exit.") 1382 | continue 1383 | 1384 | first_embed.add_field(name="Max amount", value=f"{max_amount}") 1385 | first_embed.set_footer(text="Type cancel to quit or skip to skip this option") 1386 | next_info = ":seven: What role(s) must the user already have in order to buy this item?\nIf none, just reply `skip`. For multiple, ping the roles with a space between them." 1387 | await last_report.edit(content=next_info, embed=first_embed) 1388 | checkpoints += 1 1389 | 1390 | elif checkpoints == 7: 1391 | # check 7: required role 1392 | try: 1393 | if user_input in ["skip", "none"]: 1394 | raise ValueError 1395 | 1396 | roles_clean_one = await get_role_id_multiple(user_input) 1397 | 1398 | required_roles = "" 1399 | for role_id in roles_clean_one: 1400 | try: 1401 | role = discord.utils.get(server.roles, id=int(role_id)) 1402 | print(role) 1403 | required_roles += f"{str(role.mention)} " 1404 | except: 1405 | await channel.send(f"{emoji_error} Invalid role given. Please try again.") 1406 | raise NameError 1407 | 1408 | except NameError: 1409 | continue 1410 | 1411 | except ValueError: 1412 | if user_input in ["skip", "none"]: 1413 | required_roles = ["none"] 1414 | 1415 | except Exception as e: 1416 | await channel.send(f"{emoji_error} Invalid role given. Please try again.") 1417 | continue 1418 | try: 1419 | roles_id_required = roles_clean_one 1420 | print(roles_id_required) 1421 | except: 1422 | roles_id_required = ["none"] 1423 | first_embed.add_field(name="Role required", value=f"{required_roles}") 1424 | first_embed.set_footer(text="Type cancel to quit or skip to skip this option") 1425 | next_info = ":eight: What roles should make purchase of this item impossible ? (excluded role(s))?\nIf none, just reply `skip`. For multiple, ping them with a space between them." 1426 | await last_report.edit(content=next_info, embed=first_embed) 1427 | checkpoints += 1 1428 | 1429 | elif checkpoints == 8: 1430 | # check 8: excluded role - meaning you cant buy if possessing it. 1431 | try: 1432 | if user_input in ["skip", "none"]: 1433 | raise ValueError 1434 | 1435 | roles_clean_two = await get_role_id_multiple(user_input) 1436 | 1437 | excluded_roles = "" 1438 | for role_id in roles_clean_two: 1439 | try: 1440 | role = discord.utils.get(server.roles, id=int(role_id)) 1441 | print(role) 1442 | excluded_roles += f"{str(role.mention)} " 1443 | except: 1444 | await channel.send(f"{emoji_error} Invalid role given. Please try again.") 1445 | raise NameError 1446 | 1447 | except NameError: 1448 | continue 1449 | 1450 | except ValueError: 1451 | if user_input in ["skip", "none"]: 1452 | excluded_roles = ["none"] 1453 | 1454 | except Exception as e: 1455 | await channel.send(f"{emoji_error} Invalid role given. Please try again.") 1456 | continue 1457 | try: 1458 | roles_id_excluded = roles_clean_two 1459 | print(roles_id_excluded) 1460 | except: 1461 | roles_id_excluded = ["none"] 1462 | first_embed.add_field(name="Excluded roles", value=f"{excluded_roles}") 1463 | first_embed.set_footer(text="Type cancel to quit or skip to skip this option") 1464 | next_info = ":nine: What role(s) do you want to be given when this item is bought?\nIf none, just reply `skip`. For multiple, ping them with a space between them." 1465 | await last_report.edit(content=next_info, embed=first_embed) 1466 | checkpoints += 1 1467 | 1468 | elif checkpoints == 9: 1469 | # check 9: role to be given when item bought 1470 | try: 1471 | if user_input in ["skip", "none"]: 1472 | raise ValueError 1473 | 1474 | roles_clean_three = await get_role_id_multiple(user_input) 1475 | 1476 | roles_give = "" 1477 | for role_id in roles_clean_three: 1478 | try: 1479 | role = discord.utils.get(server.roles, id=int(role_id)) 1480 | print(role) 1481 | roles_give += f"{str(role.mention)} " 1482 | except: 1483 | await channel.send(f"{emoji_error} Invalid role given. Please try again.") 1484 | raise NameError 1485 | 1486 | except NameError: 1487 | continue 1488 | 1489 | except ValueError: 1490 | if user_input in ["skip", "none"]: 1491 | roles_give = ["none"] 1492 | 1493 | except Exception as e: 1494 | await channel.send(f"{emoji_error} Invalid role given. Please try again.") 1495 | continue 1496 | 1497 | try: 1498 | roles_id_to_give = roles_clean_three 1499 | except: 1500 | roles_id_to_give = ["none"] 1501 | first_embed.add_field(name="Role given", value=f"{roles_give}") 1502 | first_embed.set_footer(text="Type cancel to quit or skip to skip this option") 1503 | next_info = ":keycap_ten: What role(s) do you want to be removed from the user when this item is bought?\nIf none, just reply `skip`. For multiple, ping with a space between them." 1504 | await last_report.edit(content=next_info, embed=first_embed) 1505 | checkpoints += 1 1506 | 1507 | elif checkpoints == 10: 1508 | # check 10: role to be removed when item bought 1509 | try: 1510 | if user_input in ["skip", "none"]: 1511 | raise ValueError 1512 | 1513 | roles_clean_four = await get_role_id_multiple(user_input) 1514 | 1515 | roles_remove = "" 1516 | for role_id in roles_clean_four: 1517 | try: 1518 | role = discord.utils.get(server.roles, id=int(role_id)) 1519 | print(role) 1520 | roles_remove += f"{str(role.mention)} " 1521 | except: 1522 | await channel.send(f"{emoji_error} Invalid role given. Please try again.") 1523 | raise NameError 1524 | 1525 | except NameError as b: 1526 | print(b) 1527 | continue 1528 | 1529 | except ValueError: 1530 | if user_input in ["skip", "none"]: 1531 | roles_remove = ["none"] 1532 | 1533 | except Exception as e: 1534 | await channel.send(f"{emoji_error} Invalid role given. Please try again.") 1535 | continue 1536 | 1537 | try: 1538 | roles_id_to_remove = roles_clean_four 1539 | except: 1540 | roles_id_to_remove = ["none"] 1541 | first_embed.add_field(name="Role removed", value=f"{roles_remove}") 1542 | first_embed.set_footer(text="Type cancel to quit or skip to skip this option") 1543 | next_info = "`11` What is the maximum balanace a user can have in order to buy this item?\nIf none, just reply `skip`." 1544 | await last_report.edit(content=next_info, embed=first_embed) 1545 | checkpoints += 1 1546 | 1547 | elif checkpoints == 11: 1548 | # check 11: max balance 1549 | try: 1550 | max_bal = int(user_input) 1551 | if max_bal < 1: 1552 | await channel.send(f"{emoji_error} Invalid max balance given. Please try again or type cancel to exit.") 1553 | continue 1554 | except: 1555 | if user_input.lower() == "skip": 1556 | max_bal = "none" 1557 | else: 1558 | await channel.send(f"{emoji_error} Invalid max balance given. Please try again or type cancel to exit.") 1559 | continue 1560 | first_embed.add_field(name="Maximum balance", value=f"{max_bal}") 1561 | first_embed.set_footer(text="Type cancel to quit or skip to skip this option") 1562 | next_info = "`12`: What message do you want the bot to reply with, when the item is bought?\nIf none, just reply `skip`." 1563 | await last_report.edit(content=next_info, embed=first_embed) 1564 | checkpoints += 1 1565 | 1566 | elif checkpoints == 12: 1567 | # check 12: reply message 1568 | if len(user_input) > 150: 1569 | await channel.send(f"{emoji_error} The maximum length for a reply message is 150 characters. Please try again.") 1570 | continue 1571 | if user_input.lower() == "skip": 1572 | user_input = f"Congrats on buying the item." 1573 | reply_message = user_input 1574 | first_embed.add_field(name="Reply message", value=f"{reply_message}", inline=False) 1575 | first_embed.set_footer(text="Type cancel to quit or skip to skip this option") 1576 | next_info = "`13`: What image should the item have? Enter complete url !\nIf none, just reply `skip`." 1577 | await last_report.edit(content=next_info, embed=first_embed) 1578 | checkpoints += 1 1579 | 1580 | elif checkpoints == 13: 1581 | # check 13: item img 1582 | if user_input.lower() == "skip": 1583 | user_input = f"EMPTY" 1584 | item_img_url = user_input 1585 | else: 1586 | try: 1587 | rq = requests.get(user_input) 1588 | except: 1589 | await channel.send(f"{emoji_error} URL not found. Please try again or skip.") 1590 | continue 1591 | 1592 | if rq.status_code != 200: 1593 | await channel.send(f"{emoji_error} URL not found. Please try again or skip.") 1594 | continue 1595 | item_img_url = user_input 1596 | first_embed.set_thumbnail(url=item_img_url) 1597 | next_info = f"{emoji_worked} Item created successfully!" 1598 | await last_report.edit(content=next_info, embed=first_embed) 1599 | checkpoints = -1 1600 | # finished with the checks 1601 | currently_creating_item = False 1602 | 1603 | # handler 1604 | 1605 | try: 1606 | status, create_item_return = await db_handler.create_new_item(item_display_name, item_name, cost, description, duration, stock, max_amount, roles_id_required, roles_id_to_give, roles_id_to_remove, max_bal, reply_message, item_img_url, roles_id_excluded) 1607 | if status == "error": 1608 | color = discord_error_rgb_code 1609 | embed = discord.Embed(description=f"{create_item_return}", color=color) 1610 | embed.set_author(name=username, icon_url=user_pfp) 1611 | await channel.send(embed=embed) 1612 | return 1613 | except Exception as e: 1614 | print(e) 1615 | await send_error(channel) 1616 | 1617 | # --------------------------- 1618 | # DELETE ITEM - REMOVE ITEM 1619 | # --------------------------- 1620 | 1621 | elif command in ["delete-item", "remove-item"]: 1622 | if not staff_request: 1623 | color = discord_error_rgb_code 1624 | embed = discord.Embed(description=f"🔒 Requires botmaster role", color=color) 1625 | embed.set_author(name=username, icon_url=user_pfp) 1626 | await channel.send(embed=embed) 1627 | return 1628 | 1629 | if "none" in param[1]: # we need 1 parameters 1630 | color = discord_error_rgb_code 1631 | embed = discord.Embed(description=f"{emoji_error} Too few arguments given.\n\nUsage:\n`delete-item `", color=color) 1632 | embed.set_author(name=username, icon_url=user_pfp) 1633 | await channel.send(embed=embed) 1634 | return 1635 | 1636 | item_name = param[1] 1637 | 1638 | # since this will completely remove the item 1639 | # we should make sure you rly want to do this (and not remove-user-item). 1640 | security_check = False 1641 | sec_embed = discord.Embed(title="Attention", description="🚨 This will permanently delete the item, also for every user!\nDo you wish to continue? [y/N]", color=discord.Color.from_rgb(3, 169, 244)) 1642 | sec_embed.set_footer(text="Info: use remove-user-item to remove an item from a specific user.") 1643 | await channel.send(embed=sec_embed) 1644 | 1645 | security_check_input = await get_user_input(message) 1646 | if security_check_input.strip().lower() not in ["yes", "y"]: 1647 | await channel.send(f"{emoji_error} Cancelled command.") 1648 | return 1649 | 1650 | # handler 1651 | 1652 | try: 1653 | status, remove_item_return = await db_handler.remove_item(item_name) 1654 | if status == "error": 1655 | color = discord_error_rgb_code 1656 | embed = discord.Embed(description=f"{remove_item_return}", color=color) 1657 | embed.set_author(name=username, icon_url=user_pfp) 1658 | await channel.send(embed=embed) 1659 | return 1660 | except Exception as e: 1661 | print(e) 1662 | await send_error(channel) 1663 | 1664 | color = discord.Color.from_rgb(102, 187, 106) # green 1665 | embed = discord.Embed(description=f"{emoji_worked} Item has been removed from the store.\nNote: also deletes from everyone's inventory.", color=color) 1666 | embed.set_author(name=username, icon_url=user_pfp) 1667 | await channel.send(embed=embed) 1668 | 1669 | return 1670 | 1671 | # --------------------------- 1672 | # REMOVE USER ITEM 1673 | # --------------------------- 1674 | 1675 | elif command in ["remove-user-item"]: 1676 | if not staff_request: 1677 | color = discord_error_rgb_code 1678 | embed = discord.Embed(description=f"🔒 Requires botmaster role", color=color) 1679 | embed.set_author(name=username, icon_url=user_pfp) 1680 | await channel.send(embed=embed) 1681 | return 1682 | 1683 | if "none" in param[1]: # we need player pinged 1684 | color = discord_error_rgb_code 1685 | embed = discord.Embed(description=f"{emoji_error} Too few arguments given.\n\nUsage:\n`remove-user-item `", color=color) 1686 | embed.set_author(name=username, icon_url=user_pfp) 1687 | await channel.send(embed=embed) 1688 | return 1689 | 1690 | player_ping = await get_user_id(param) 1691 | 1692 | try: 1693 | user_fetch = client.get_user(int(player_ping)) 1694 | print(user_fetch) 1695 | reception_user_name = user_fetch 1696 | 1697 | except: 1698 | # we didnt find him 1699 | color = discord_error_rgb_code 1700 | embed = discord.Embed(description=f"{emoji_error} Invalid `` argument given.\n\nUsage:" 1701 | f"\n`remove-user-item `", color=color) 1702 | embed.set_author(name=username, icon_url=user_pfp) 1703 | await channel.send(embed=embed) 1704 | return 1705 | 1706 | if "none" in param[2]: # we need item name 1707 | color = discord_error_rgb_code 1708 | embed = discord.Embed(description=f"{emoji_error} Too few arguments given.\n\nUsage:\n`remove-user-item `", color=color) 1709 | embed.set_author(name=username, icon_url=user_pfp) 1710 | await channel.send(embed=embed) 1711 | return 1712 | item_name = param[2] 1713 | 1714 | if "none" in param[3]: # we need item amount 1715 | amount = 1 1716 | else: 1717 | amount = param[3] 1718 | 1719 | try: 1720 | amount = int(amount) 1721 | if amount < 1: 1722 | color = discord_error_rgb_code 1723 | embed = discord.Embed(description=f"{emoji_error} Invalid `amount` given.\n\nUsage:\n`remove-user-item ", color=color) 1724 | embed.set_author(name=username, icon_url=user_pfp) 1725 | await channel.send(embed=embed) 1726 | return 1727 | except: 1728 | color = discord_error_rgb_code 1729 | embed = discord.Embed(description=f"{emoji_error} Invalid `amount` given.\n\nUsage:\n`remove-user-item `", color=color) 1730 | embed.set_author(name=username, icon_url=user_pfp) 1731 | await channel.send(embed=embed) 1732 | return 1733 | 1734 | # handler 1735 | 1736 | try: 1737 | status, remove_user_item_return = await db_handler.remove_user_item(user, channel, username, user_pfp, item_name, amount, player_ping, reception_user_name) 1738 | if status == "error": 1739 | color = discord_error_rgb_code 1740 | embed = discord.Embed(description=f"{remove_user_item_return}", color=color) 1741 | embed.set_author(name=username, icon_url=user_pfp) 1742 | await channel.send(embed=embed) 1743 | return 1744 | except Exception as e: 1745 | print(e) 1746 | await send_error(channel) 1747 | return 1748 | 1749 | # --------------------------- 1750 | # REMOVE GONE USERS 1751 | # --------------------------- 1752 | 1753 | elif command in ["clean-leaderboard", "clean-lb"]: 1754 | if not staff_request: 1755 | color = discord_error_rgb_code 1756 | embed = discord.Embed(description=f"🔒 Requires botmaster role", color=color) 1757 | embed.set_author(name=username, icon_url=user_pfp) 1758 | await channel.send(embed=embed) 1759 | return 1760 | 1761 | # since this will completely remove those users 1762 | # we should make sure you rly want to do this. 1763 | security_check = False 1764 | sec_embed = discord.Embed(title="Attention", description="🚨 This will permanently delete all user instances that left the server!\nDo you wish to continue? [y/N]", color=discord.Color.from_rgb(3, 169, 244)) 1765 | await channel.send(embed=sec_embed) 1766 | 1767 | security_check_input = await get_user_input(message) 1768 | if security_check_input.strip().lower() not in ["yes", "y"]: 1769 | await channel.send(f"{emoji_error} Cancelled command.") 1770 | return 1771 | 1772 | # handler 1773 | 1774 | try: 1775 | status, clean_lb_return = await db_handler.clean_leaderboard(server) 1776 | if status == "error": 1777 | color = discord_error_rgb_code 1778 | embed = discord.Embed(description=f"{clean_lb_return}", color=color) 1779 | embed.set_author(name=username, icon_url=user_pfp) 1780 | await channel.send(embed=embed) 1781 | return 1782 | except Exception as e: 1783 | print(e) 1784 | await send_error(channel) 1785 | return 1786 | 1787 | color = discord.Color.from_rgb(102, 187, 106) # green 1788 | embed = discord.Embed(description=f"{emoji_worked} {clean_lb_return} user(s) have been removed from database.", color=color) 1789 | embed.set_author(name=username, icon_url=user_pfp) 1790 | await channel.send(embed=embed) 1791 | 1792 | return 1793 | 1794 | 1795 | # --------------------------- 1796 | # BUY ITEM 1797 | # --------------------------- 1798 | 1799 | elif command in ["buy-item", "get-item", "buy"]: 1800 | # idk why i said you need botmaster to buy items ? 1801 | """ 1802 | if not staff_request: 1803 | color = discord_error_rgb_code 1804 | embed = discord.Embed(description=f"🔒 Requires botmaster role", color=color) 1805 | embed.set_author(name=username, icon_url=user_pfp) 1806 | await channel.send(embed=embed) 1807 | return 1808 | """ 1809 | 1810 | if "none" in param[1]: # we need item name 1811 | color = discord_error_rgb_code 1812 | embed = discord.Embed(description=f"{emoji_error} Too few arguments given.\n\nUsage:\n`buy-item `", color=color) 1813 | embed.set_author(name=username, icon_url=user_pfp) 1814 | await channel.send(embed=embed) 1815 | return 1816 | item_name = param[1] 1817 | 1818 | if "none" in param[2]: # we need item amount 1819 | amount = 1 1820 | else: 1821 | amount = param[2] 1822 | 1823 | try: 1824 | amount = int(amount) 1825 | if amount < 1: 1826 | color = discord_error_rgb_code 1827 | embed = discord.Embed(description=f"{emoji_error} Invalid `amount` given.\n\nUsage:\n`buy-item `", color=color) 1828 | embed.set_author(name=username, icon_url=user_pfp) 1829 | await channel.send(embed=embed) 1830 | return 1831 | except: 1832 | color = discord_error_rgb_code 1833 | embed = discord.Embed(description=f"{emoji_error} Invalid `amount` given.\n\nUsage:\n`buy-item `", color=color) 1834 | embed.set_author(name=username, icon_url=user_pfp) 1835 | await channel.send(embed=embed) 1836 | return 1837 | 1838 | # handler 1839 | user_role_ids = [randomvar.id for randomvar in message.author.roles] 1840 | 1841 | try: 1842 | status, buy_item_return = await db_handler.buy_item(user, channel, username, user_pfp, item_name, amount, user_role_ids, server, message.author) 1843 | if status == "error": 1844 | color = discord_error_rgb_code 1845 | embed = discord.Embed(description=f"{buy_item_return}", color=color) 1846 | embed.set_author(name=username, icon_url=user_pfp) 1847 | await channel.send(embed=embed) 1848 | return 1849 | except Exception as e: 1850 | print(e) 1851 | await send_error(channel) 1852 | return 1853 | 1854 | # --------------------------- 1855 | # GIVE ITEM -- can also be used to "sell" 1856 | # but theyll need to not fuck each other and actually pay up 1857 | # --------------------------- 1858 | 1859 | elif command in ["give-item"]: 1860 | """ 1861 | if not staff_request: 1862 | color = discord_error_rgb_code 1863 | embed = discord.Embed(description=f"🔒 Requires botmaster role", color=color) 1864 | embed.set_author(name=username, icon_url=user_pfp) 1865 | await channel.send(embed=embed) 1866 | return 1867 | """ 1868 | 1869 | if "none" in param[1]: # we need player pinged 1870 | color = discord_error_rgb_code 1871 | embed = discord.Embed(description=f"{emoji_error} Too few arguments given.\n\nUsage:\n`give-item `", color=color) 1872 | embed.set_author(name=username, icon_url=user_pfp) 1873 | await channel.send(embed=embed) 1874 | return 1875 | 1876 | player_ping = await get_user_id(param) 1877 | 1878 | try: 1879 | user_fetch = client.get_user(int(player_ping)) 1880 | print(user_fetch) 1881 | reception_user_name = user_fetch 1882 | print(reception_user_name) 1883 | 1884 | if int(player_ping) == user: 1885 | # cannot send money to yourself 1886 | color = discord_error_rgb_code 1887 | embed = discord.Embed(description=f"{emoji_error} You cannot trade items with yourself. That would be pointless...", color=color) 1888 | embed.set_author(name=username, icon_url=user_pfp) 1889 | await channel.send(embed=embed) 1890 | return 1891 | 1892 | except: 1893 | # we didnt find him 1894 | color = discord_error_rgb_code 1895 | embed = discord.Embed(description=f"{emoji_error} Invalid `` argument given.\n\nUsage:" 1896 | f"\n`give-item `", color=color) 1897 | embed.set_author(name=username, icon_url=user_pfp) 1898 | await channel.send(embed=embed) 1899 | return 1900 | 1901 | if "none" in param[2]: # we need item name 1902 | color = discord_error_rgb_code 1903 | embed = discord.Embed(description=f"{emoji_error} Too few arguments given.\n\nUsage:\n`give-item `", color=color) 1904 | embed.set_author(name=username, icon_url=user_pfp) 1905 | await channel.send(embed=embed) 1906 | return 1907 | item_name = param[2] 1908 | 1909 | if "none" in param[3]: # we need item amount 1910 | amount = 1 1911 | else: 1912 | amount = param[3] 1913 | 1914 | try: 1915 | amount = int(amount) 1916 | if amount < 1: 1917 | color = discord_error_rgb_code 1918 | embed = discord.Embed(description=f"{emoji_error} Invalid `amount` given.\n\nUsage:\n`give-item `", color=color) 1920 | embed.set_author(name=username, icon_url=user_pfp) 1921 | await channel.send(embed=embed) 1922 | return 1923 | except: 1924 | color = discord_error_rgb_code 1925 | embed = discord.Embed(description=f"{emoji_error} Invalid `amount` given.\n\nUsage:\n`give-item `", color=color) 1926 | embed.set_author(name=username, icon_url=user_pfp) 1927 | await channel.send(embed=embed) 1928 | return 1929 | 1930 | # handler 1931 | 1932 | try: 1933 | status, give_item_return = await db_handler.give_item(user, channel, username, user_pfp, item_name, amount, player_ping, server, message.author, reception_user_name, False) # false is for spawn_mode = False 1934 | if status == "error": 1935 | color = discord_error_rgb_code 1936 | embed = discord.Embed(description=f"{give_item_return}", color=color) 1937 | embed.set_author(name=username, icon_url=user_pfp) 1938 | await channel.send(embed=embed) 1939 | return 1940 | except Exception as e: 1941 | print(e) 1942 | await send_error(channel) 1943 | return 1944 | 1945 | # --------------------------- 1946 | # SPAWN ITEM 1947 | # if admins want to "give" someone an item without having to buy and then give it 1948 | # --------------------------- 1949 | 1950 | elif command in ["spawn-item"]: 1951 | if not staff_request: 1952 | color = discord_error_rgb_code 1953 | embed = discord.Embed(description=f"🔒 Requires botmaster role", color=color) 1954 | embed.set_author(name=username, icon_url=user_pfp) 1955 | await channel.send(embed=embed) 1956 | return 1957 | 1958 | 1959 | if "none" in param[1]: # we need player pinged 1960 | color = discord_error_rgb_code 1961 | embed = discord.Embed(description=f"{emoji_error} Too few arguments given.\n\nUsage:\n`spawn-item [amount]`", color=color) 1962 | embed.set_author(name=username, icon_url=user_pfp) 1963 | await channel.send(embed=embed) 1964 | return 1965 | 1966 | player_ping = await get_user_id(param) 1967 | 1968 | try: 1969 | user_fetch = client.get_user(int(player_ping)) 1970 | print(user_fetch) 1971 | reception_user_name = user_fetch 1972 | print(reception_user_name) 1973 | 1974 | except: 1975 | # we didnt find him 1976 | color = discord_error_rgb_code 1977 | embed = discord.Embed(description=f"{emoji_error} Invalid `` argument given.\n\nUsage:" 1978 | f"\n`spawn-item [amount]`", color=color) 1979 | embed.set_author(name=username, icon_url=user_pfp) 1980 | await channel.send(embed=embed) 1981 | return 1982 | 1983 | if "none" in param[2]: # we need item name 1984 | color = discord_error_rgb_code 1985 | embed = discord.Embed(description=f"{emoji_error} Too few arguments given.\n\nUsage:\n`spawn-item [amount]`", color=color) 1986 | embed.set_author(name=username, icon_url=user_pfp) 1987 | await channel.send(embed=embed) 1988 | return 1989 | item_name = param[2] 1990 | 1991 | if "none" in param[3]: # we need item amount 1992 | amount = 1 1993 | else: 1994 | amount = param[3] 1995 | 1996 | try: 1997 | amount = int(amount) 1998 | if amount < 1: 1999 | color = discord_error_rgb_code 2000 | embed = discord.Embed(description=f"{emoji_error} Invalid `amount` given.\n\nUsage:\n`spawn-item [amount]`", color=color) 2001 | embed.set_author(name=username, icon_url=user_pfp) 2002 | await channel.send(embed=embed) 2003 | return 2004 | except: 2005 | color = discord_error_rgb_code 2006 | embed = discord.Embed(description=f"{emoji_error} Invalid `amount` given.\n\nUsage:\n`spawn-item [amount]`", color=color) 2007 | embed.set_author(name=username, icon_url=user_pfp) 2008 | await channel.send(embed=embed) 2009 | return 2010 | 2011 | # handler 2012 | 2013 | try: 2014 | status, give_item_return = await db_handler.give_item(user, channel, username, user_pfp, item_name, amount, player_ping, server, message.author, reception_user_name, True) # True is for spawn_mode = True 2015 | if status == "error": 2016 | color = discord_error_rgb_code 2017 | embed = discord.Embed(description=f"{give_item_return}", color=color) 2018 | embed.set_author(name=username, icon_url=user_pfp) 2019 | await channel.send(embed=embed) 2020 | return 2021 | except Exception as e: 2022 | print(e) 2023 | await send_error(channel) 2024 | return 2025 | 2026 | # -------------- 2027 | # USE ITEM # this will MERELY remove the item from inventory 2028 | # -------------- 2029 | 2030 | elif command in ["use", all_reg_commands_aliases["use"]]: # no alias 2031 | 2032 | if "none" in param[1]: # we need an item used 2033 | color = discord_error_rgb_code 2034 | embed = discord.Embed(description=f"{emoji_error} Too few arguments given.\n\nUsage:\n`use-item `", color=color) 2035 | embed.set_author(name=username, icon_url=user_pfp) 2036 | await channel.send(embed=embed) 2037 | return 2038 | else: 2039 | item_used = param[1] 2040 | 2041 | if "none" in param[2]: # we need item amount 2042 | amount_used = 1 # by default it will be 1 2043 | else: 2044 | amount_used = param[2] 2045 | try: 2046 | amount_used = int(amount_used) 2047 | except: 2048 | color = discord_error_rgb_code 2049 | embed = discord.Embed( 2050 | description=f"{emoji_error} Amount must be a (whole) integer.\n\nUsage:\n`use-item `", 2051 | color=color) 2052 | embed.set_author(name=username, icon_url=user_pfp) 2053 | await channel.send(embed=embed) 2054 | return 2055 | 2056 | try: 2057 | status, use_return = await db_handler.use_item(user, channel, username, user_pfp, item_used, amount_used) 2058 | 2059 | if status == "error": 2060 | color = discord_error_rgb_code 2061 | embed = discord.Embed(description=f"{use_return}", color=color) 2062 | embed.set_author(name=username, icon_url=user_pfp) 2063 | await channel.send(embed=embed) 2064 | return 2065 | 2066 | except Exception as e: 2067 | print(e) 2068 | await send_error(channel) 2069 | 2070 | # --------------------------------------- 2071 | # CHECK INVENTORY (check own inventory) 2072 | # --------------------------------------- 2073 | 2074 | elif command in ["inventory"]: 2075 | # by default, you look at your own inventory. 2076 | # this is prob useless and its easier to just put user_to_check_uname=none in the func init.py 2077 | # but for now this will do 2078 | user_to_check, user_to_check_uname, user_to_check_pfp = "self", "self", "self" 2079 | # or if for another member 2080 | if param[1] == "none": 2081 | page_number = 1 2082 | else: 2083 | try: 2084 | page_number = int(param[1]) 2085 | except: 2086 | color = discord_error_rgb_code 2087 | embed = discord.Embed( 2088 | description=f"{emoji_error} Invalid page number.\n\nUsage:\n`inventory [page]`", color=color) 2089 | embed.set_footer(text="info: use it without page once, output will show amount of total pages.\ninfo: use user-inventory to see inventory of another user.") 2090 | embed.set_author(name=username, icon_url=user_pfp) 2091 | await channel.send(embed=embed) 2092 | return 2093 | 2094 | # handler 2095 | 2096 | try: 2097 | status, inventory_return = await db_handler.check_inventory(user, channel, username, user_pfp, user_to_check, user_to_check_uname, user_to_check_pfp, page_number) 2098 | if status == "error": 2099 | color = discord_error_rgb_code 2100 | embed = discord.Embed(description=f"{inventory_return}", color=color) 2101 | embed.set_author(name=username, icon_url=user_pfp) 2102 | await channel.send(embed=embed) 2103 | return 2104 | except Exception as e: 2105 | print(e) 2106 | await send_error(channel) 2107 | return 2108 | 2109 | # -------------------------------------------------------- 2110 | # CHECK USER INVENTORY (check inventory of another user) 2111 | # -------------------------------------------------------- 2112 | 2113 | elif command in ["user-inventory"]: 2114 | # by default, you look at your own inventory. 2115 | # this is prob useless and its easier to just put user_to_check_uname=none in the func init.py 2116 | # but for now this will do 2117 | # or if for another member 2118 | 2119 | if "none" in param[1]: # we need a member pinged 2120 | color = discord_error_rgb_code 2121 | embed = discord.Embed(description=f"{emoji_error} Too few arguments given.\n\nUsage:\n`user-inventory [page]`", color=color) 2122 | embed.set_footer(text="info: use `inventory` to see your own inventory.") 2123 | embed.set_author(name=username, icon_url=user_pfp) 2124 | await channel.send(embed=embed) 2125 | return 2126 | else: 2127 | # to get his id 2128 | user_to_check = await get_user_id(param) 2129 | 2130 | try: 2131 | # used for @-mention. 2132 | 2133 | user_to_check_uname_b = client.get_user(int(user_to_check)) 2134 | user_to_check_uname = user_to_check_uname_b.name # idk why we need this but without it breaks 2135 | user_to_check_pfp = user_to_check_uname_b.display_avatar 2136 | if int(user_to_check) == user: 2137 | user_to_check, user_to_check_uname, user_to_check_pfp = "self", "self", "self" 2138 | except: 2139 | # we didnt find him 2140 | color = discord_error_rgb_code 2141 | embed = discord.Embed( 2142 | description=f"{emoji_error} Invalid member ping.\n\nUsage:\n`user-inventory [page]`", color=color) 2143 | embed.set_footer(text="info: use `inventory` to see your own inventory.") 2144 | embed.set_author(name=username, icon_url=user_pfp) 2145 | await channel.send(embed=embed) 2146 | return 2147 | 2148 | if param[2] == "none": 2149 | page_number = 1 2150 | else: 2151 | try: 2152 | page_number = int(param[2]) 2153 | except Exception as error_code: 2154 | print(error_code) 2155 | color = discord_error_rgb_code 2156 | embed = discord.Embed( 2157 | description=f"{emoji_error} Invalid page number.\n\nUsage:\n`user-inventory [page]`", color=color) 2158 | embed.set_footer(text="info: use it without page once, output will show amount of total pages") 2159 | embed.set_author(name=username, icon_url=user_pfp) 2160 | await channel.send(embed=embed) 2161 | return 2162 | 2163 | 2164 | 2165 | # handler 2166 | 2167 | try: 2168 | status, inventory_return = await db_handler.check_inventory(user, channel, username, user_pfp, user_to_check, user_to_check_uname, user_to_check_pfp, page_number) 2169 | if status == "error": 2170 | color = discord_error_rgb_code 2171 | embed = discord.Embed(description=f"{inventory_return}", color=color) 2172 | embed.set_author(name=username, icon_url=user_pfp) 2173 | await channel.send(embed=embed) 2174 | return 2175 | except Exception as e: 2176 | print(e) 2177 | await send_error(channel) 2178 | return 2179 | 2180 | # --------------------------- 2181 | # ITEMS CATALOG 2182 | # --------------------------- 2183 | 2184 | elif command in ["catalog", "items", "item-list", "list-items"]: 2185 | 2186 | if "none" in param[1]: # we need item name 2187 | item_check = "default_list" 2188 | else: 2189 | item_check = param[1] 2190 | 2191 | # handler 2192 | try: 2193 | status, catalog_return = await db_handler.catalog(user, channel, username, user_pfp, item_check, server) 2194 | if status == "error": 2195 | color = discord_error_rgb_code 2196 | embed = discord.Embed(description=f"{catalog_return}", color=color) 2197 | embed.set_author(name=username, icon_url=user_pfp) 2198 | await channel.send(embed=embed) 2199 | return 2200 | except Exception as e: 2201 | print(e) 2202 | await send_error(channel) 2203 | return 2204 | 2205 | 2206 | # --------------------------- 2207 | # ADD ROLE INCOME ROLE 2208 | # --------------------------- 2209 | 2210 | elif command in ["add-income-role", "add-role-income"]: 2211 | await channel.send("Info: the income amount specified is an DAILY one.\nRemember: you need to manually update income.") 2212 | if not staff_request: 2213 | color = discord_error_rgb_code 2214 | embed = discord.Embed(description=f"🔒 Requires botmaster role", color=color) 2215 | embed.set_author(name=username, icon_url=user_pfp) 2216 | await channel.send(embed=embed) 2217 | return 2218 | 2219 | if "none" in param[1] or "none" in param[2]: # we need 3 parameters 2220 | color = discord_error_rgb_code 2221 | embed = discord.Embed(description=f"{emoji_error} Too few arguments given.\n\nUsage:\n`add-income-role `", color=color) 2222 | embed.set_author(name=username, icon_url=user_pfp) 2223 | await channel.send(embed=embed) 2224 | return 2225 | 2226 | # check role 2227 | 2228 | 2229 | income_role = await get_role_id_single(param[1]) 2230 | 2231 | try: 2232 | role = discord.utils.get(server.roles, id=int(income_role)) 2233 | except Exception as e: 2234 | print(e) 2235 | await channel.send(f"{emoji_error} Invalid role given.") 2236 | return 2237 | 2238 | # check amount 2239 | amount = param[2] 2240 | # they can use the thousands separator comma 2241 | try: 2242 | newAmount = [] 2243 | for char in amount: 2244 | if char != ",": 2245 | newAmount.append(char) 2246 | amount = "".join(newAmount) 2247 | amount = int(amount) 2248 | if amount < 1: 2249 | color = discord_error_rgb_code 2250 | embed = discord.Embed( 2251 | description=f"{emoji_error} Invalid `` argument given.\n\nUsage:\n`add-income-role `", 2252 | color=color) 2253 | embed.set_author(name=username, icon_url=user_pfp) 2254 | await channel.send(embed=embed) 2255 | return 2256 | except: 2257 | color = discord_error_rgb_code 2258 | embed = discord.Embed(description=f"{emoji_error} Invalid `` argument given.\n\nUsage:\n`add-income-role `", color=color) 2259 | embed.set_author(name=username, icon_url=user_pfp) 2260 | await channel.send(embed=embed) 2261 | return 2262 | 2263 | # handler 2264 | try: 2265 | status, create_role_return = await db_handler.new_income_role(user, channel, username, user_pfp, income_role, amount) 2266 | if status == "error": 2267 | color = discord_error_rgb_code 2268 | embed = discord.Embed(description=f"{create_role_return}", color=color) 2269 | embed.set_author(name=username, icon_url=user_pfp) 2270 | await channel.send(embed=embed) 2271 | return 2272 | except Exception as e: 2273 | print(e) 2274 | await send_error(channel) 2275 | return 2276 | 2277 | # --------------------------- 2278 | # REMOVE ROLE 2279 | # --------------------------- 2280 | 2281 | elif command in ["remove-income-role", "delete-income-role", "remove-role-income", "delete-role-income"]: 2282 | if not staff_request: 2283 | color = discord_error_rgb_code 2284 | embed = discord.Embed(description=f"🔒 Requires botmaster role", color=color) 2285 | embed.set_author(name=username, icon_url=user_pfp) 2286 | await channel.send(embed=embed) 2287 | return 2288 | 2289 | if "none" in param[1]: # we need 1 parameters 2290 | color = discord_error_rgb_code 2291 | embed = discord.Embed(description=f"{emoji_error} Too few arguments given.\n\nUsage:\n`remove-income-role `", color=color) 2292 | embed.set_author(name=username, icon_url=user_pfp) 2293 | await channel.send(embed=embed) 2294 | return 2295 | 2296 | # check role 2297 | 2298 | income_role_beta = str(param[1]) # see another instance where i use this to see why 2299 | income_role = "" 2300 | for i in range(len(income_role_beta)): 2301 | try: 2302 | income_role += str(int(income_role_beta[i])) 2303 | except: 2304 | pass 2305 | 2306 | try: 2307 | role = discord.utils.get(server.roles, id=int(income_role)) 2308 | except Exception as e: 2309 | print(e) 2310 | await channel.send(f"{emoji_error} Invalid role given. Please try again.") 2311 | return 2312 | 2313 | # handler 2314 | try: 2315 | status, remove_role_return = await db_handler.remove_income_role(user, channel, username, user_pfp, income_role) 2316 | if status == "error": 2317 | color = discord_error_rgb_code 2318 | embed = discord.Embed(description=f"{remove_role_return}", color=color) 2319 | embed.set_author(name=username, icon_url=user_pfp) 2320 | await channel.send(embed=embed) 2321 | return 2322 | except Exception as e: 2323 | print(e) 2324 | await send_error(channel) 2325 | 2326 | color = discord.Color.from_rgb(102, 187, 106) # green 2327 | embed = discord.Embed(description=f"{emoji_worked} Role has been disabled as income role.", color=color) 2328 | embed.set_author(name=username, icon_url=user_pfp) 2329 | await channel.send(embed=embed) 2330 | 2331 | return 2332 | 2333 | # --------------------------- 2334 | # REMOVE MONEY BY ROLE 2335 | # --------------------------- 2336 | 2337 | elif command in ["remove-money-role", "remove-role-money"]: 2338 | if not staff_request: 2339 | color = discord_error_rgb_code 2340 | embed = discord.Embed(description=f"🔒 Requires botmaster role", color=color) 2341 | embed.set_author(name=username, icon_url=user_pfp) 2342 | await channel.send(embed=embed) 2343 | return 2344 | 2345 | if "none" in param[1] or "none" in param[2]: # we need 2 parameters 2346 | color = discord_error_rgb_code 2347 | embed = discord.Embed( 2348 | description=f"{emoji_error} Too few arguments given.\n\nUsage:\n`remove-money-role `", 2349 | color=color) 2350 | embed.set_author(name=username, icon_url=user_pfp) 2351 | await channel.send(embed=embed) 2352 | return 2353 | 2354 | amount = param[2] 2355 | try: 2356 | # they can use the thousands separator comma 2357 | newAmount = [] 2358 | for char in amount: 2359 | if char != ",": 2360 | newAmount.append(char) 2361 | amount = "".join(newAmount) 2362 | amount = int(amount) 2363 | if amount < 1: 2364 | color = discord_error_rgb_code 2365 | embed = discord.Embed( 2366 | description=f"{emoji_error} Invalid `` argument given.\n\nUsage:\n`remove-money-role `", 2367 | color=color) 2368 | embed.set_author(name=username, icon_url=user_pfp) 2369 | await channel.send(embed=embed) 2370 | return 2371 | except: 2372 | color = discord_error_rgb_code 2373 | embed = discord.Embed( 2374 | description=f"{emoji_error} Invalid `` argument given.\n\nUsage:\n`remove-money-role `", 2375 | color=color) 2376 | embed.set_author(name=username, icon_url=user_pfp) 2377 | await channel.send(embed=embed) 2378 | return 2379 | 2380 | # check role 2381 | 2382 | income_role = await get_role_id_single(param[1]) 2383 | 2384 | try: 2385 | role = discord.utils.get(server.roles, id=int(income_role)) 2386 | except Exception as e: 2387 | print(e) 2388 | await channel.send(f"{emoji_error} Invalid role given. Please try again.") 2389 | return 2390 | 2391 | # handler 2392 | try: 2393 | status, remove_money_role_return = await db_handler.remove_money_role(user, channel, username, user_pfp, server, income_role, amount) 2394 | if status == "error": 2395 | color = discord_error_rgb_code 2396 | embed = discord.Embed(description=f"{remove_money_role_return}", color=color) 2397 | embed.set_author(name=username, icon_url=user_pfp) 2398 | await channel.send(embed=embed) 2399 | return 2400 | except Exception as e: 2401 | print(e) 2402 | await send_error(channel) 2403 | return 2404 | 2405 | # --------------------------- 2406 | # LIST INCOME ROLES 2407 | # --------------------------- 2408 | 2409 | elif command in ["list-roles", "list-income-roles", "list-role-income", "list-incomes"]: 2410 | try: 2411 | status, list_roles_return = await db_handler.list_income_roles(user, channel, username, user_pfp, server) 2412 | if status == "error": 2413 | color = discord_error_rgb_code 2414 | embed = discord.Embed(description=f"{list_roles_return}", color=color) 2415 | embed.set_author(name=username, icon_url=user_pfp) 2416 | await channel.send(embed=embed) 2417 | return 2418 | except Exception as e: 2419 | print(e) 2420 | await send_error(channel) 2421 | return 2422 | 2423 | # --------------------------- 2424 | # UPDATE INCOMES 2425 | # --------------------------- 2426 | 2427 | elif command in ["update-income"]: 2428 | if not staff_request: 2429 | color = discord_error_rgb_code 2430 | embed = discord.Embed(description=f"🔒 Requires botmaster role", color=color) 2431 | embed.set_author(name=username, icon_url=user_pfp) 2432 | await channel.send(embed=embed) 2433 | return 2434 | 2435 | try: 2436 | status, update_incomes_return = await db_handler.update_incomes(user, channel, username, user_pfp, server) 2437 | if status == "error": 2438 | color = discord_error_rgb_code 2439 | embed = discord.Embed(description=f"{update_incomes_return}", color=color) 2440 | embed.set_author(name=username, icon_url=user_pfp) 2441 | await channel.send(embed=embed) 2442 | return 2443 | except Exception as e: 2444 | print(e) 2445 | await send_error(channel) 2446 | 2447 | color = discord.Color.from_rgb(102, 187, 106) # green 2448 | embed = discord.Embed(description=f"{emoji_worked} Users with registered roles have received their income (into bank account).", color=color) 2449 | embed.set_author(name=username, icon_url=user_pfp) 2450 | await channel.send(embed=embed) 2451 | 2452 | return 2453 | 2454 | 2455 | # --------------------------- 2456 | # UPDATE INCOME FOR YOURSELF ONLY 2457 | # --------------------------- 2458 | 2459 | elif command in ["collect", "get-salary", "update-income-solo"]: 2460 | 2461 | try: 2462 | status, update_incomes_return = await db_handler.update_incomes_solo(user, channel, username, user_pfp, server, user_roles) 2463 | if status == "error": 2464 | color = discord_error_rgb_code 2465 | embed = discord.Embed(description=f"{update_incomes_return}", color=color) 2466 | embed.set_author(name=username, icon_url=user_pfp) 2467 | await channel.send(embed=embed) 2468 | return 2469 | except Exception as e: 2470 | print(e) 2471 | await send_error(channel) 2472 | 2473 | """ 2474 | color = discord.Color.from_rgb(102, 187, 106) # green 2475 | embed = discord.Embed(description=f"{emoji_worked} You have received {update_incomes_return} for your roles {roles_return} (into bank account).", color=color) 2476 | embed.set_author(name=username, icon_url=user_pfp) 2477 | await channel.send(embed=embed) 2478 | """ 2479 | return 2480 | 2481 | 2482 | # --------------------------- 2483 | # economy stats 2484 | # --------------------------- 2485 | 2486 | elif command in ["stats", "economy-stats", "statistics"]: 2487 | 2488 | try: 2489 | status, economy_stats_return = await db_handler.economy_stats(user, channel, username, user_pfp, server) 2490 | if status == "error": 2491 | color = discord_error_rgb_code 2492 | embed = discord.Embed(description=f"{economy_stats_return}", color=color) 2493 | embed.set_author(name=username, icon_url=user_pfp) 2494 | await channel.send(embed=embed) 2495 | return 2496 | except Exception as e: 2497 | print(e) 2498 | await send_error(channel) 2499 | 2500 | 2501 | return 2502 | 2503 | 2504 | """ 2505 | END OF CODE. 2506 | -> starting bot 2507 | """ 2508 | 2509 | print("Starting bot") 2510 | client.run(token) 2511 | --------------------------------------------------------------------------------