import random
import re
from core.conn import Conn
from core.db import DB
from core.decorators import instance
from core.logger import Logger
from core.lookup.character_service import CharacterService
from core.setting_service import SettingService
from core.text import Text
from core.tyrbot import Tyrbot
@instance("DingController")
class DingController:
axp = re.compile(
r"ICC planet-wide announcement: (.+) has been awarded the highest honorary rank for "
r"outstanding dedication to the defence of Rubi-Ka.")
xp = re.compile(
r"You feel the core of your being shift, as the source makes room for a divine presence. "
r"'(.+)' has reached enlightenment.")
text_options_xp = ["Congratz! You have reached the end of the line! NO MORE FUN FOR YOU! :P",
"Holy shit, you finally made it! What an accomplishment... Congratulations "
"{name}, for reaching a level reserved for the greatest!",
"Damn {name}.... I'm going to miss you a great deal, "
"because after this, we no longer can be together {name}."
" We must part so you can continue getting your research and AI levels done! Farewell!",
"Hey {name}, how was the inferno grind? "
"I'm glad to see you made it through, and congratulations for "
"finally getting the level you well deserved!",
"Our congratulations, to our newest level 220 member, "
"{name}, for his dedication. "
"We present him with his new honorary rank, Chuck Norris!",
"Holy crap, you actually did it! Dear {name}, "
"I salute you for your determination and sheer awesomeness. Congratulations, "
"to our newest level 220 member!"]
text_options_axp = ["Congratz! You have reached the end of the line! NO MORE FUN FOR YOU! :P",
"Holy shit, you finally made it! What an accomplishment... "
"Congratulations {name}, "
"for reaching Alien Level 30!",
"Damn... I'm going to miss you a great deal, because after this, we no longer can be together, "
"{name}. We must part so you can continue getting your research!"
" Farewell!",
"Hey {name}, how was the alien grind?"
" I'm glad to see you made it through, "
"and congratulations for finally getting the level you well deserved!",
"Our congratulations, to our newest Alien Level 30 member, "
"{name}, for his dedication. "
"We present him with his new honorary rank, Vindicator!",
"Holy crap, you actually did it! Dear {name}, "
"I salute you for your determination and sheer awesomeness. Congratulations, "
"to our newest Alien Level 30 member!"]
def __init__(self):
self.logger = Logger(__name__)
def inject(self, registry):
self.bot: Tyrbot = registry.get_instance("bot")
self.text: Text = registry.get_instance("text")
self.setting_service: SettingService = registry.get_instance("setting_service")
self.character_service: CharacterService = registry.get_instance("character_service")
self.message_hub_service = registry.get_instance("message_hub_service")
self.db: DB = registry.get_instance("db")
def pre_start(self):
self.bot.register_packet_handler(36, self.handle_ding)
self.bot.register_packet_handler(35, self.handle_ding)
def handle_ding(self, conn: Conn, packet):
if conn.char_id != self.bot.get_char_id():
return
# AXP 30
if packet.id == 36:
info = re.findall(self.axp, packet.message)
if info:
user = self.get_user(info[0])
if user:
self.bot.send_mass_message(user.char_id,
f"Game Over! "
f"{random.choice(self.text_options_axp).format(**user)} "
f"[{self.generate_output('AI 220')}]",
log_message=True)
# XP 220
if packet.id == 35:
info = re.findall(self.xp, packet.message)
if info:
user = self.get_user(info[0])
if user:
self.bot.send_mass_message(user.char_id,
f"Game Over! "
f"{random.choice(self.text_options_xp).format(**user)} "
f"[{self.generate_output('Level 220')}]",
log_message=True)
def generate_output(self, level):
invite = self.text.make_chatcmd("click here", "/tell discord invite",
style="style='text-decoration:none'")
sys = self.text.make_chatcmd("SYSTEM", "/tell admins",
style="style='text-decoration:none'")
blob = self.text.format_page('Info',
f"
"
f"This automated message has been sent to you by:
"
f"Igncom [{sys}]
"
f"Reason for this Message: "
f"You dinged {level}
"
f"Have you joined The Alliance Discord yet? "
f"If not {invite} to receive an invite. "
f"(/tell discord invite from your Main)")
return blob
def get_user(self, name):
return self.db.query_single("SELECT * FROM player where name=? and org_id in (SELECT * from orgs)", [name])