Skip to content

Commit

Permalink
Merge pull request #59 from DogeMultiverse/make-checkexp
Browse files Browse the repository at this point in the history
Make checkexp
  • Loading branch information
alexpvpmindustry authored Dec 17, 2023
2 parents 1db9bb0 + 23e1a74 commit 6a3af1f
Show file tree
Hide file tree
Showing 5 changed files with 234 additions and 158 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ data/*
mastermelon/__pycache__
mastermelon/utils/__pycache__
logs/*
testing_code.ipynb
.ipynb_checkpoints/testing_code-checkpoint.ipynb
.ipynb_checkpoints/
.ipynb_checkpoints*
16 changes: 15 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
]
}
}
11 changes: 4 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
171 changes: 21 additions & 150 deletions mastermelon/melon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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 <EXP> <SERVER> <LASTUPDATED,UTC> <CLAIMED>\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

Expand All @@ -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",
Expand Down Expand Up @@ -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,convertedexpv6=convertedexp,expgainsv6=expgains)


@bot.command(description="Displays buyeffect menu.", brief="Utility")
Expand All @@ -701,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"],
Expand Down Expand Up @@ -969,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):
Expand Down
Loading

0 comments on commit 6a3af1f

Please sign in to comment.