From f95e391f932c68b31ed66ec6334d6c66d5347266 Mon Sep 17 00:00:00 2001 From: apmapmapm Date: Sun, 17 Dec 2023 15:39:04 +0800 Subject: [PATCH 1/7] so far so good --- .vscode/settings.json | 16 ++++- main.py | 11 ++- mastermelon/melon.py | 148 +++++--------------------------------- mastermelon/mindustry.py | 151 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 188 insertions(+), 138 deletions(-) create mode 100644 mastermelon/mindustry.py diff --git a/.vscode/settings.json b/.vscode/settings.json index 9ee86e7..ccc3d38 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,5 +2,19 @@ "[python]": { "editor.defaultFormatter": "ms-python.autopep8" }, - "python.formatting.provider": "none" + "python.formatting.provider": "none", + "actionButtons": { + "defaultColor": "#ff0034", // Can also use string color names. + "loadNpmCommands":false, // Disables automatic generation of actions for npm commands. + "reloadButton":"♻️", // Custom reload button text or icon (default ↻). null value enables automatic reload on configuration change + "commands": [ + { + "cwd": "${workspaceFolder}", // Terminal initial folder ${workspaceFolder} and os user home as defaults + "name": "Run main.py", + "color": "green", + "singleInstance": false, + "command": "python main.py", // This is executed in the terminal. + } + ] + } } \ No newline at end of file diff --git a/main.py b/main.py index a3f4cc0..0c5f814 100644 --- a/main.py +++ b/main.py @@ -1,15 +1,12 @@ -import pymongo - +# Press the green button in the gutter to run the script. +from mastermelon import melon +from datetime import datetime def print_hi(name): # Use a breakpoint in the code line below to debug your script. - print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint. + print(f'Hi, {name}, started at {datetime.utcnow()}') # Press Ctrl+F8 to toggle the breakpoint. -# Press the green button in the gutter to run the script. -from mastermelon import guessing_game -from mastermelon import melon - if __name__ == '__main__': # todo: create required folders on first initalisation # folders: logs, mods, (maybe more) diff --git a/mastermelon/melon.py b/mastermelon/melon.py index cc72845..fe1e6b9 100644 --- a/mastermelon/melon.py +++ b/mastermelon/melon.py @@ -9,7 +9,10 @@ import json from mastermelon.anti_mindus_bot import plugin_anti_bot, vkick_anti_bot from mastermelon.disc_constants import DUUID_ALEX, DUUID_WATERMELON + import pymongo +from pymongo.collection import Collection +from pymongo.database import Database import asyncio import random from discord.ext import commands @@ -23,6 +26,7 @@ from mastermelon import cookiegame from mastermelon import gen_image from mastermelon import feedback +from mastermelon import mindustry from mastermelon.utils.is_valid_guild import is_valid_guild_check, is_valid_guild from mastermelon.utils.get_user_display_name import get_user_display_name @@ -32,74 +36,6 @@ def get_date_str(): return str(datetime.now())[:-4] - -def get_latest_exp(res, convertedexp_doc): - muuid = {} - muuid_name = {} - last_updated = {} - exp_dict = {} - if convertedexp_doc is None: - convertedexp_doc = {} - for doc in res: - if doc["EXP"] is None: - doc["EXP"] = 0 - if doc["muuid"] not in muuid: - muuid[doc["muuid"]] = {doc["servername"]: doc["EXP"]} - muuid_name[doc["muuid"]] = doc["musername"] - last_updated[doc["muuid"]] = {doc["servername"]: doc["date"]} - elif (doc["servername"] in muuid[doc["muuid"]]) and (muuid[doc["muuid"]][doc["servername"]] < doc["EXP"]): - muuid[doc["muuid"]][doc["servername"]] = doc["EXP"] - muuid_name[doc["muuid"]] = doc["musername"] - last_updated[doc["muuid"]][doc["servername"]] = doc["date"] - else: - muuid[doc["muuid"]][doc["servername"]] = doc["EXP"] - last_updated[doc["muuid"]][doc["servername"]] = doc["date"] - if doc["muuid"] not in convertedexp_doc: - convertedexp_doc[doc["muuid"]] = {} - str_builder = "" - for muuid_i, exps in muuid.items(): - str_builder += "In Game Name: `" + muuid_name[muuid_i] + "`\n" - exp_builder = "" - muuid_exp_dict = {"In_Game_Name": muuid_name[muuid_i], "servers": []} - for server, exp in sorted(list(exps.items()), - key=lambda x: 0 if isinstance(x[1], type(None)) else x[1], reverse=True): - if server in ["ALEX | PVP (USA)", "ALEX | PVP (ASIA)", "ALEX | ATTACK (USA)", "ALEX | SURVIVAL (ASIA)"]: - try: - exp = 0 if exp is None else exp - rservername = server[7:].replace(" SERVER", "") - serverstr = rservername + ( - " [TOP 1%]" if exp > 40000 else (" [TOP 10%]" if exp > 15000 else "")) - if server[7:].replace(" SERVER", "") not in convertedexp_doc[muuid_i]: - convertedexp_doc[muuid_i][rservername] = { - "claimed": 0, "lcdate": None} - claimed = 0 - lcdate = None - else: - claimed = convertedexp_doc[muuid_i][rservername]["claimed"] - lcdate = convertedexp_doc[muuid_i][rservername]["lcdate"] - if last_updated[muuid_i][server] < datetime(2023, 8, 8): - legacy_server = True - else: - legacy_server = False - exp_builder += f"{exp:>6} " + f"{serverstr:<21}" + \ - last_updated[muuid_i][server].strftime( - "%Y-%m-%d %H:%M") + f" {claimed:<6} "+("(legacy server)" if legacy_server else "") + "\n" - muuid_exp_dict["servers"].append({"servername": rservername, - "exp": exp, "claimed": claimed, "lcdate": lcdate, - "lupdated": last_updated[muuid_i][server], - "legacy_server": legacy_server - }) - except Exception as e: - print(exp, server) - print(str(e)) - if len(exp_builder) > 0: - exp_builder = "```\n \n" + \ - exp_builder + "\n```" - str_builder += exp_builder - exp_dict[muuid_i] = muuid_exp_dict - return str_builder, exp_dict, convertedexp_doc - - intents = discord.Intents.default() intents.members = True @@ -115,16 +51,20 @@ def get_latest_exp(res, convertedexp_doc): if prefix in ["w?", "t?"]: # only access mongodb for w? and t? client = pymongo.MongoClient(mongo_key) - db = client.get_database("AlexMindustry") - expgains = db["expgains"] - convertedexp = db["convertedexp"] - ax = db["ax"] - ingamecosmetics = db["ingamecosmetics"] + db: Database = client.get_database("AlexMindustry") + expgains: Collection = db["expgains"] + convertedexp: Collection = db["convertedexp"] + # V7 stuff + expv7: Collection = db["expv7"] + convertedexpv7: Collection = db["convertedexpv7"] + ingamecosmeticsv7: Collection = db["ingamecosmeticsv7"] + + ax: Collection = db["ax"] ipaddress_access_key: str = js["ipaddress_access_key"] - serverplayerupdates = db["serverplayerupdates"] - discordinvites: pymongo.collection = db["discordinvites"] - registerpin: pymongo.collection = db["registerpin"] - duuid1: pymongo.collection = db["duuid1"] + serverplayerupdates: Collection = db["serverplayerupdates"] + discordinvites: Collection = db["discordinvites"] + registerpin: Collection = db["registerpin"] + duuid1: Collection = db["duuid1"] invitecode_mapping = {"KPVVsj2MGW": "Alex Mindustry Invite", "BnBf2STAAd": "Doge Youtube Invite", "GSdkpZZuxN": "Doge Youtube Premium Invite", "BmCssqnhX6": "Alex TOP MC Invite", @@ -640,59 +580,7 @@ def is_correct(m): @bot.command(description="Check user's registered account's EXP", brief="Utility") @commands.check(is_valid_guild) async def checkexp(ctx: discord.ext.commands.Context, user: discord.User = None): - if prefix == "t?" and ctx.author.id != DUUID_ALEX: - await ctx.channel.send("no testing for u") - return - elif True: - await ctx.channel.send("check exp is down. come back later.") - return - if isinstance(user, type(None)): - userTarget = ctx.author.id - else: - userTarget = user.id - await ctx.channel.send('getting exp', delete_after=3) - cursor = expgains.find({"duuid": userTarget}) - convertedexp_doc = convertedexp.find_one({"duuid": userTarget}) - if convertedexp_doc is None: - convertedexp.insert_one({"duuid": userTarget, "converted": None}) - else: - convertedexp_doc = convertedexp_doc["converted"] - res = [] - for i, cur in enumerate(cursor): - res.append(cur) - if len(res) == 0: - print("User has no EXP.") - await ctx.channel.send("User has no EXP or user not found.") - else: - str_builder, exp_dict, convertedexp_doc = get_latest_exp( - res, convertedexp_doc) - if len(str_builder) > 0: - convertedexp.find_one_and_replace({"duuid": userTarget}, - {"duuid": userTarget, "converted": convertedexp_doc}) - - # todo count the amount of unconverted exp and trigger the next line if there is - if len(str_builder) >= 1850: - temp_str_builder = "" - sent = False - for i, strr in enumerate(str_builder.split("In Game Name: ")): - if i != 0: - temp_str_builder += "In Game Name: " + strr - sent = False - if i % 3 == 0: - await ctx.channel.send(temp_str_builder) - sent = True - temp_str_builder = "" - if not sent: - await ctx.channel.send(temp_str_builder) - await ctx.channel.send(f"\n Type `{prefix}convertexp` to convert your EXP into {ej.ax_emoji}." - f"(You still can keep your EXP)") - else: - await ctx.channel.send( - str_builder + - f"\n Type `{prefix}convertexp` to convert your EXP into {ej.ax_emoji}." - f"(You still can keep your EXP)") - else: - await ctx.channel.send("You have no exp. ;-;") + await mindustry.checkexp(ctx,user,prefix,expv7,convertedexpv7) @bot.command(description="Displays buyeffect menu.", brief="Utility") diff --git a/mastermelon/mindustry.py b/mastermelon/mindustry.py new file mode 100644 index 0000000..6ed7cc9 --- /dev/null +++ b/mastermelon/mindustry.py @@ -0,0 +1,151 @@ +import pymongo +from mastermelon.disc_constants import DUUID_ALEX +import discord +from pymongo.collection import Collection +from datetime import timedelta +from datetime import datetime + +from mastermelon import emojis as ej + +def get_latest_exp(res, convertedexp_doc): + muuid = {} + muuid_name = {} + last_updated = {} + exp_dict = {} + if convertedexp_doc is None: + convertedexp_doc = {} + for doc in res: + if doc["EXP"] is None: + doc["EXP"] = 0 + if doc["muuid"] not in muuid: + muuid[doc["muuid"]] = {doc["servername"]: doc["EXP"]} + muuid_name[doc["muuid"]] = doc["musername"] + last_updated[doc["muuid"]] = {doc["servername"]: doc["date"]} + elif (doc["servername"] in muuid[doc["muuid"]]) and (muuid[doc["muuid"]][doc["servername"]] < doc["EXP"]): + muuid[doc["muuid"]][doc["servername"]] = doc["EXP"] + muuid_name[doc["muuid"]] = doc["musername"] + last_updated[doc["muuid"]][doc["servername"]] = doc["date"] + else: + muuid[doc["muuid"]][doc["servername"]] = doc["EXP"] + last_updated[doc["muuid"]][doc["servername"]] = doc["date"] + if doc["muuid"] not in convertedexp_doc: + convertedexp_doc[doc["muuid"]] = {} + str_builder = "" + for muuid_i, exps in muuid.items(): + str_builder += "In Game Name: `" + muuid_name[muuid_i] + "`\n" + exp_builder = "" + muuid_exp_dict = {"In_Game_Name": muuid_name[muuid_i], "servers": []} + for server, exp in sorted(list(exps.items()), + key=lambda x: 0 if isinstance(x[1], type(None)) else x[1], reverse=True): + if server in ["ALEX | PVP (USA)", "ALEX | PVP (ASIA)", "ALEX | ATTACK (USA)", "ALEX | SURVIVAL (ASIA)"]: + try: + exp = 0 if exp is None else exp + rservername = server[7:].replace(" SERVER", "") + serverstr = rservername + ( + " [TOP 1%]" if exp > 40000 else (" [TOP 10%]" if exp > 15000 else "")) + if server[7:].replace(" SERVER", "") not in convertedexp_doc[muuid_i]: + convertedexp_doc[muuid_i][rservername] = { + "claimed": 0, "lcdate": None} + claimed = 0 + lcdate = None + else: + claimed = convertedexp_doc[muuid_i][rservername]["claimed"] + lcdate = convertedexp_doc[muuid_i][rservername]["lcdate"] + if last_updated[muuid_i][server] < datetime(2023, 8, 8): + legacy_server = True + else: + legacy_server = False + exp_builder += f"{exp:>6} " + f"{serverstr:<21}" + \ + last_updated[muuid_i][server].strftime( + "%Y-%m-%d %H:%M") + f" {claimed:<6} "+("(legacy server)" if legacy_server else "") + "\n" + muuid_exp_dict["servers"].append({"servername": rservername, + "exp": exp, "claimed": claimed, "lcdate": lcdate, + "lupdated": last_updated[muuid_i][server], + "legacy_server": legacy_server + }) + except Exception as e: + print(exp, server) + print(str(e)) + if len(exp_builder) > 0: + exp_builder = "```\n \n" + \ + exp_builder + "\n```" + str_builder += exp_builder + exp_dict[muuid_i] = muuid_exp_dict + return str_builder, exp_dict, convertedexp_doc + + +async def checkexp(ctx: discord.ext.commands.Context, user: discord.User, prefix: str, expgains: Collection, convertedexp: Collection): + if prefix == "t?" and ctx.author.id != DUUID_ALEX: + await ctx.channel.send("no testing for u") + return + if isinstance(user, type(None)): + userTarget = ctx.author.id + else: + userTarget = user.id + await ctx.channel.send('getting exp', delete_after=3) + + exp_doc : pymongo.Documents = expgains.find_one({"duuid": userTarget},{"_id": 0, "musername": 1, "EXP": 1, "servers": 1}) + if exp_doc is None: + await ctx.channel.send("User has no EXP or user not found.") + return + convertedexp_doc : pymongo.Documents = convertedexp.find_one({"duuid": userTarget}) + if convertedexp_doc is None: + convertedexp_doc = {"duuid": userTarget, "convertedexp": 0, "lastconvertdate":datetime.utcnow() } + convertedexp.insert_one(convertedexp_doc) + # convertedexp_doc should have 3 fields. + await ctx.channel.send(convertedexp_doc) + # await ctx.channel.send(exp_doc["musername"]+" "+len(exp_doc["servers"])+" exp"+exp_doc["EXP"]) + await ctx.channel.send(f'{exp_doc["musername"]} {len(exp_doc["servers"])} exp {exp_doc["EXP"]}') + + +async def checkexp_legacy(ctx: discord.ext.commands.Context, user: discord.User, prefix: str, expgains: Collection, convertedexp: Collection): + if prefix == "t?" and ctx.author.id != DUUID_ALEX: + await ctx.channel.send("no testing for u") + return + if isinstance(user, type(None)): + userTarget = ctx.author.id + else: + userTarget = user.id + await ctx.channel.send('getting exp', delete_after=3) + cursor = expgains.find({"duuid": userTarget}) + convertedexp_doc = convertedexp.find_one({"duuid": userTarget}) + if convertedexp_doc is None: + convertedexp.insert_one({"duuid": userTarget, "converted": None}) + else: + convertedexp_doc = convertedexp_doc["converted"] + res = [] + for i, cur in enumerate(cursor): + res.append(cur) + if len(res) == 0: + print("User has no EXP.") + await ctx.channel.send("User has no EXP or user not found.") + else: + str_builder, exp_dict, convertedexp_doc = get_latest_exp( + res, convertedexp_doc) + if len(str_builder) > 0: + convertedexp.find_one_and_replace({"duuid": userTarget}, + {"duuid": userTarget, "converted": convertedexp_doc}) + + # todo count the amount of unconverted exp and trigger the next line if there is + if len(str_builder) >= 1850: + temp_str_builder = "" + sent = False + for i, strr in enumerate(str_builder.split("In Game Name: ")): + if i != 0: + temp_str_builder += "In Game Name: " + strr + sent = False + if i % 3 == 0: + await ctx.channel.send(temp_str_builder) + sent = True + temp_str_builder = "" + if not sent: + await ctx.channel.send(temp_str_builder) + await ctx.channel.send(f"\n Type `{prefix}convertexp` to convert your EXP into {ej.ax_emoji}." + f"(You still can keep your EXP)") + else: + await ctx.channel.send( + str_builder + + f"\n Type `{prefix}convertexp` to convert your EXP into {ej.ax_emoji}." + f"(You still can keep your EXP)") + else: + await ctx.channel.send("You have no exp. ;-;") \ No newline at end of file From e3190ef7a89af0fca98aa6bf618fed818e5edf14 Mon Sep 17 00:00:00 2001 From: apmapmapm Date: Sun, 17 Dec 2023 16:59:35 +0800 Subject: [PATCH 2/7] migrate from prev version --- mastermelon/mindustry.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mastermelon/mindustry.py b/mastermelon/mindustry.py index 6ed7cc9..514b6ac 100644 --- a/mastermelon/mindustry.py +++ b/mastermelon/mindustry.py @@ -4,6 +4,7 @@ from pymongo.collection import Collection from datetime import timedelta from datetime import datetime +from collections import Counter from mastermelon import emojis as ej @@ -89,14 +90,13 @@ async def checkexp(ctx: discord.ext.commands.Context, user: discord.User, prefix await ctx.channel.send("User has no EXP or user not found.") return convertedexp_doc : pymongo.Documents = convertedexp.find_one({"duuid": userTarget}) - if convertedexp_doc is None: - convertedexp_doc = {"duuid": userTarget, "convertedexp": 0, "lastconvertdate":datetime.utcnow() } + if convertedexp_doc is None: + convertedexp_doc = {"duuid": userTarget, "convertedexp": int(exp_doc["EXP"])//2, "lastconvertdate":datetime.utcnow() } convertedexp.insert_one(convertedexp_doc) # convertedexp_doc should have 3 fields. - await ctx.channel.send(convertedexp_doc) - # await ctx.channel.send(exp_doc["musername"]+" "+len(exp_doc["servers"])+" exp"+exp_doc["EXP"]) - await ctx.channel.send(f'{exp_doc["musername"]} {len(exp_doc["servers"])} exp {exp_doc["EXP"]}') - + await ctx.channel.send(f'current exp: {exp_doc["EXP"]}\nconverted exp: {convertedexp_doc["convertedexp"]}\nlast converted: {convertedexp_doc["lastconvertdate"]}') + # TODO make this formating better + # await ctx.channel.send(Counter(exp_doc["servers"]).items()) async def checkexp_legacy(ctx: discord.ext.commands.Context, user: discord.User, prefix: str, expgains: Collection, convertedexp: Collection): if prefix == "t?" and ctx.author.id != DUUID_ALEX: From 43d27ba0b73a1a9c1f491c596bcfd3d5d88c87aa Mon Sep 17 00:00:00 2001 From: apmapmapm Date: Sun, 17 Dec 2023 17:03:18 +0800 Subject: [PATCH 3/7] wip --- mastermelon/mindustry.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/mastermelon/mindustry.py b/mastermelon/mindustry.py index 514b6ac..fe943b7 100644 --- a/mastermelon/mindustry.py +++ b/mastermelon/mindustry.py @@ -83,7 +83,7 @@ async def checkexp(ctx: discord.ext.commands.Context, user: discord.User, prefix userTarget = ctx.author.id else: userTarget = user.id - await ctx.channel.send('getting exp', delete_after=3) + await ctx.channel.send('Getting exp', delete_after=3) exp_doc : pymongo.Documents = expgains.find_one({"duuid": userTarget},{"_id": 0, "musername": 1, "EXP": 1, "servers": 1}) if exp_doc is None: @@ -94,10 +94,21 @@ async def checkexp(ctx: discord.ext.commands.Context, user: discord.User, prefix convertedexp_doc = {"duuid": userTarget, "convertedexp": int(exp_doc["EXP"])//2, "lastconvertdate":datetime.utcnow() } convertedexp.insert_one(convertedexp_doc) # convertedexp_doc should have 3 fields. - await ctx.channel.send(f'current exp: {exp_doc["EXP"]}\nconverted exp: {convertedexp_doc["convertedexp"]}\nlast converted: {convertedexp_doc["lastconvertdate"]}') + await ctx.channel.send(f'Current EXP: `{exp_doc["EXP"]}`\nConverted EXP: `{convertedexp_doc["convertedexp"]}`\nLast converted: `{convertedexp_doc["lastconvertdate"]}`\nUse `{prefix}convertexp` to convert your EXP to {ej.ax_emoji}. You will still keep your EXP.') # TODO make this formating better # await ctx.channel.send(Counter(exp_doc["servers"]).items()) +async def convertexp(ctx: discord.ext.commands.Context, user: discord.User, prefix: str, expgains: Collection, convertedexp: Collection): + if prefix == "t?" and ctx.author.id != DUUID_ALEX: + await ctx.channel.send("no testing for u") + return + if isinstance(user, type(None)): + userTarget = ctx.author.id + else: + userTarget = user.id + await ctx.channel.send('Converting exp', delete_after=3) + + async def checkexp_legacy(ctx: discord.ext.commands.Context, user: discord.User, prefix: str, expgains: Collection, convertedexp: Collection): if prefix == "t?" and ctx.author.id != DUUID_ALEX: await ctx.channel.send("no testing for u") From d516ddd18386bb671609f0c43ad63504a09d5355 Mon Sep 17 00:00:00 2001 From: apmapmapm Date: Mon, 18 Dec 2023 00:14:37 +0800 Subject: [PATCH 4/7] add ignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 51a6fce..290650e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ data/* mastermelon/__pycache__ mastermelon/utils/__pycache__ logs/* +testing_code.ipynb \ No newline at end of file From d92d6c25ff14791ce136927707ab0492b2370803 Mon Sep 17 00:00:00 2001 From: apmapmapm Date: Mon, 18 Dec 2023 00:15:15 +0800 Subject: [PATCH 5/7] 1 --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 290650e..4834e60 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ data/* mastermelon/__pycache__ mastermelon/utils/__pycache__ logs/* -testing_code.ipynb \ No newline at end of file +testing_code.ipynb +.ipynb_checkpoints/testing_code-checkpoint.ipynb From da0365de9252563ccdaab29a6879bacca33d41dd Mon Sep 17 00:00:00 2001 From: apmapmapm Date: Mon, 18 Dec 2023 00:15:48 +0800 Subject: [PATCH 6/7] 2 --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 4834e60..fb32b37 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ mastermelon/utils/__pycache__ logs/* testing_code.ipynb .ipynb_checkpoints/testing_code-checkpoint.ipynb +.ipynb_checkpoints/ +.ipynb_checkpoints* \ No newline at end of file From 23e1a74142e55c968a37e2f1fbdd8d342e8173f2 Mon Sep 17 00:00:00 2001 From: apmapmapm Date: Mon, 18 Dec 2023 00:44:47 +0800 Subject: [PATCH 7/7] 2 --- mastermelon/melon.py | 25 ++++--------------------- mastermelon/mindustry.py | 40 ++++++++++++++++++++++++++++++++++------ 2 files changed, 38 insertions(+), 27 deletions(-) diff --git a/mastermelon/melon.py b/mastermelon/melon.py index fe1e6b9..33f3414 100644 --- a/mastermelon/melon.py +++ b/mastermelon/melon.py @@ -580,7 +580,7 @@ def is_correct(m): @bot.command(description="Check user's registered account's EXP", brief="Utility") @commands.check(is_valid_guild) async def checkexp(ctx: discord.ext.commands.Context, user: discord.User = None): - await mindustry.checkexp(ctx,user,prefix,expv7,convertedexpv7) + await mindustry.checkexp(ctx,user,prefix,expv7,convertedexpv7,convertedexpv6=convertedexp,expgainsv6=expgains) @bot.command(description="Displays buyeffect menu.", brief="Utility") @@ -589,6 +589,9 @@ async def buyeffect(ctx: discord.ext.commands.Context, peffect: str = None): if prefix == "t?" and ctx.author.id != DUUID_ALEX: await ctx.channel.send("t? is only for alex to test") return + elif True: + await ctx.channel.send("Effects coming soon") + return await ctx.channel.send("Fetching effects...", delete_after=2) effects_cost = {20: ["yellowDiamond", "yellowSquare", "yellowCircle"], 30: ["greenCircle", "whiteDoor", "yellowLargeDiam", "yellowSpark"], @@ -857,26 +860,6 @@ async def giveaway(ctx: discord.ext.commands.Context, what: str, channel: discor await ctx.channel.send("invalid command usage") -@bot.command() -@commands.check(is_valid_guild) -async def feedback(ctx): - if True: - return - button = ui.Button( - label="Write", style=discord.ButtonStyle.primary) # create_button - view = ui.View() # create view - view.add_item(button) # add to view button - - async def button_callback(interaction: discord.Interaction): # on button_click - modal = feedback.MyModal(title="FeedBack") - await interaction.response.send_modal(modal) # open the modal window - - button.callback = button_callback - embed = discord.Embed(title="What would you like to add to the mindustry or discord server", - description="Send a message to the developers", color=discord.Color.red()) - await ctx.channel.send(embed=embed, view=view) - - @bot.command(description=f"Convert user's exp into {ej.ax_emoji}.", brief="Utility") @commands.check(is_valid_guild) async def convertexp(ctx: discord.ext.commands.Context, member: discord.Member = None): diff --git a/mastermelon/mindustry.py b/mastermelon/mindustry.py index fe943b7..3f940e5 100644 --- a/mastermelon/mindustry.py +++ b/mastermelon/mindustry.py @@ -75,7 +75,8 @@ def get_latest_exp(res, convertedexp_doc): return str_builder, exp_dict, convertedexp_doc -async def checkexp(ctx: discord.ext.commands.Context, user: discord.User, prefix: str, expgains: Collection, convertedexp: Collection): +async def checkexp(ctx: discord.ext.commands.Context, user: discord.User, prefix: str, expgains: Collection, + convertedexp: Collection, convertedexpv6: Collection, expgainsv6: Collection): if prefix == "t?" and ctx.author.id != DUUID_ALEX: await ctx.channel.send("no testing for u") return @@ -90,13 +91,40 @@ async def checkexp(ctx: discord.ext.commands.Context, user: discord.User, prefix await ctx.channel.send("User has no EXP or user not found.") return convertedexp_doc : pymongo.Documents = convertedexp.find_one({"duuid": userTarget}) - if convertedexp_doc is None: - convertedexp_doc = {"duuid": userTarget, "convertedexp": int(exp_doc["EXP"])//2, "lastconvertdate":datetime.utcnow() } + EXP = exp_doc["EXP"] + if convertedexp_doc is None: + latest_claim = get_latest_claim(userTarget,convertedexpv6,expgainsv6) + latest_claim = min(EXP,latest_claim) + convertedexp_doc = {"duuid": userTarget, "convertedexp": latest_claim, "lastconvertdate":datetime.utcnow() } convertedexp.insert_one(convertedexp_doc) # convertedexp_doc should have 3 fields. - await ctx.channel.send(f'Current EXP: `{exp_doc["EXP"]}`\nConverted EXP: `{convertedexp_doc["convertedexp"]}`\nLast converted: `{convertedexp_doc["lastconvertdate"]}`\nUse `{prefix}convertexp` to convert your EXP to {ej.ax_emoji}. You will still keep your EXP.') - # TODO make this formating better - # await ctx.channel.send(Counter(exp_doc["servers"]).items()) + str_time=convertedexp_doc["lastconvertdate"].strftime("%a %d %b %Y, %I:%M%p")+" (UTC)" + await ctx.channel.send( f'Current EXP: `{EXP:,}`\n'\ + f'Converted EXP: `{convertedexp_doc["convertedexp"]:,}`\n'\ + f'Last converted: `{str_time}`\n'\ + f'Use `{prefix}convertexp` to convert your EXP to {ej.ax_emoji}. You will still keep your EXP.' + ) + # TODO make this formating better + +async def convertexp(ctx: discord.ext.commands.Context, user: discord.User, prefix: str, expgains: Collection, + convertedexp: Collection, convertedexpv6: Collection, expgainsv6: Collection): + await ctx.channel.send(f'Coming soon...') + +def get_latest_claim(duuid,convertedexpv6,expgainsv6): + docs = expgainsv6.find({"duuid":duuid}).sort("EXP",-1).limit(1) + servername="" + for d in docs: + servername=d["servername"] + latest_claim = 0 + docs2 = convertedexpv6.find({"duuid":duuid}).limit(1) + for d in docs2: + for muuid,docc in d["converted"].items(): + if servername[7:] in docc: + claimed = docc[servername[7:] ]["claimed"] + if claimed>latest_claim: + latest_claim=claimed + return latest_claim + async def convertexp(ctx: discord.ext.commands.Context, user: discord.User, prefix: str, expgains: Collection, convertedexp: Collection): if prefix == "t?" and ctx.author.id != DUUID_ALEX: