Initial Release of IGNCore version 2.5
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
{
|
||||
"invite_fail": {
|
||||
"en_US": "<highlight>{target}</highlight> is already in the private channel.",
|
||||
"de_DE": "Der Spieler <highlight>{target}</highlight> ist bereits ein MItglied des privaten Channels."
|
||||
},
|
||||
"invite_success_target": {
|
||||
"en_US": "You have been invited to the private channel by <highlight>{inviter}</highlight>.",
|
||||
"de_DE": "Du wurdest von <highlight>{inviter}</highlight> zu meinem privaten Channel eingeladen."
|
||||
},
|
||||
"invite_success_self": {
|
||||
"en_US": "You have invited <highlight>{target}</highlight> to the private channel.",
|
||||
"de_DE": "Du hast <highlight>{target}</highlight> erfolgreich in den privaten Channel eingeladen."
|
||||
},
|
||||
"kick_success_target": {
|
||||
"en_US": "You have been kicked from the private channel by <highlight>{kicker}</highlight>.",
|
||||
"de_DE": "Du wurdest von <highlight>{kicker}</highlight> aus dem privaten Channel gekickt."
|
||||
},
|
||||
"kick_success_self": {
|
||||
"en_US": "You have kicked <highlight>{target}</highlight> from the private channel.",
|
||||
"de_DE": "Du hast <highlight>{target}</highlight> aus dem privaten Channel gekickt."
|
||||
},
|
||||
"kick_fail": {
|
||||
"en_US": "You do not have the required access level to kick <highlight>{target}</highlight>.",
|
||||
"de_DE": "Du hast nicht das benötigte Zugriffslevel, um <highlight>{target}</highlight> zu kicken."
|
||||
},
|
||||
"kick_fail_not_in_priv": {
|
||||
"en_US": "<highlight>{target}</highlight> is not an member of the private channel.",
|
||||
"de_DE": "<highlight>{target}</highlight> ist kein Mitglied des privaten Channels."
|
||||
},
|
||||
"join": {
|
||||
"en_US": "{char} has joined the private channel. {logon}",
|
||||
"de_DE": "<orange>Online<end>: {char}. {logon}"
|
||||
},
|
||||
"leave": {
|
||||
"en_US": "<highlight>{char}</highlight> has left the private channel. {logoff}",
|
||||
"de_DE": "<highlight>{char}</highlight> hat <yellow>sich nach</yellow> <red>Terra</red> <blue>gebeamt.</blue> {logoff}"
|
||||
},
|
||||
"kick_all": {
|
||||
"en_US": "Everyone will be kicked from this channel in 10 seconds. [by <highlight>{char}</highlight>]",
|
||||
"de_DE": "In 10 Sekunden wird jeder aus dem Channel gekickt. [von <highlight>{char}</highlight>]"
|
||||
},
|
||||
"mem_add_fail": {
|
||||
"en_US": "<highlight>{char}</highlight> is already a member.",
|
||||
"de_DE": "<highlight>{char}</highlight> ist bereits ein Mitglied."
|
||||
},
|
||||
"mem_add_success": {
|
||||
"en_US": "<highlight>{char}</highlight> has been added as a member.",
|
||||
"de_DE": "<highlight>{char}</highlight> wurde als Mitglied hinzugefügt."
|
||||
},
|
||||
"mem_rem_success": {
|
||||
"en_US": "<highlight>{char}</highlight> has been removed as a member.",
|
||||
"de_DE": "<highlight>{char}</highlight> wurde als Mitglied entfernt."
|
||||
},
|
||||
"mem_rem_fail": {
|
||||
"en_US": "<highlight>{char}</highlight> is not a member.",
|
||||
"de_DE": "<highlight>{char}</highlight> ist kein Mitglied."
|
||||
},
|
||||
"blob_mem_list": {
|
||||
"en_US": "Members ({amount})",
|
||||
"de_DE": "Mitglieder ({amount})"
|
||||
},
|
||||
"autoinvite_changed": {
|
||||
"en_US": "Your auto invite preference has been set to <highlight>{changedto}</highlight>.",
|
||||
"de_DE": "Deine Autoinvite Einstellung ist nun <highlight>{changedto}</highlight>."
|
||||
},
|
||||
"not_an_member": {
|
||||
"en_US": "You must be a member of this bot to set your auto invite preference.",
|
||||
"de_DE": "Du musst ein Mitglied des Bots sein, um deine Autoinvite Einstellung zu setzen."
|
||||
},
|
||||
"auto_invited": {
|
||||
"en_US": "You have been auto-invited to the private channel.",
|
||||
"de_DE": "Du wurdest automatsich in meinen privaten Channel eingeladen."
|
||||
},
|
||||
"on": {
|
||||
"en_US": "on",
|
||||
"de_DE": "an"
|
||||
},
|
||||
"off": {
|
||||
"en_US": "off",
|
||||
"de_DE": "aus"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,246 @@
|
||||
import hjson
|
||||
|
||||
from core.buddy_service import BuddyService
|
||||
from core.chat_blob import ChatBlob
|
||||
from core.command_param_types import Character, Multiple
|
||||
from core.db import DB, SqlException
|
||||
from core.decorators import instance, command, event
|
||||
from core.dict_object import DictObject
|
||||
from core.lookup.character_service import CharacterService
|
||||
from core.lookup.pork_service import PorkService
|
||||
from core.private_channel_service import PrivateChannelService
|
||||
from core.setting_service import SettingService
|
||||
from core.text import Text
|
||||
from core.translation_service import TranslationService
|
||||
from core.tyrbot import Tyrbot
|
||||
from core.util import Util
|
||||
from modules.core.accounting.services.account_service import AccountService
|
||||
from modules.core.ban.ban_service import BanService
|
||||
from modules.standard.online.online_display import OnlineDisplay
|
||||
|
||||
|
||||
@instance()
|
||||
class PrivateChannelController:
|
||||
MESSAGE_SOURCE = "private_channel"
|
||||
PRIVATE_CHANNEL_PREFIX = "[<cyan>Priv</cyan>] "
|
||||
|
||||
def inject(self, registry):
|
||||
self.bot: Tyrbot = registry.get_instance("bot")
|
||||
self.util: Util = registry.get_instance("util")
|
||||
self.private_channel_service = registry.get_instance("private_channel_service")
|
||||
self.character_service: CharacterService = registry.get_instance("character_service")
|
||||
self.pork: PorkService = registry.get_instance("pork_service")
|
||||
self.job_scheduler = registry.get_instance("job_scheduler")
|
||||
self.access_service = registry.get_instance("access_service")
|
||||
self.message_hub_service = registry.get_instance("message_hub_service")
|
||||
self.ban_service = registry.get_instance("ban_service")
|
||||
self.text: Text = registry.get_instance("text")
|
||||
self.ts: TranslationService = registry.get_instance("translation_service")
|
||||
self.getresp = self.ts.get_response
|
||||
self.setting_service: SettingService = registry.get_instance("setting_service")
|
||||
self.buddy_service: BuddyService = registry.get_instance("buddy_service")
|
||||
self.account_service: AccountService = registry.get_instance("account_service")
|
||||
self.db: DB = registry.get_instance("db")
|
||||
self.priv: PrivateChannelService = registry.get_instance("private_channel_service")
|
||||
|
||||
def pre_start(self):
|
||||
self.db.create_view("online")
|
||||
self.message_hub_service.register_message_source(self.MESSAGE_SOURCE)
|
||||
|
||||
try:
|
||||
self.reinvite = [x.char_id for x in
|
||||
self.db.query("SELECT char_id from online where channel = ?", [self.bot.name])]
|
||||
|
||||
except SqlException:
|
||||
self.reinvite = []
|
||||
|
||||
def start(self):
|
||||
self.message_hub_service.register_message_destination(self.MESSAGE_SOURCE,
|
||||
self.handle_incoming_relay_message,
|
||||
["registration"],
|
||||
[self.MESSAGE_SOURCE])
|
||||
self.ts.register_translation("module/private_channel", self.load_private_channel_msg)
|
||||
|
||||
@event("connect", "Reinvite previous raiders")
|
||||
def reinvite_all(self, _, _1):
|
||||
for user in self.reinvite:
|
||||
self.bot.send_mass_message(user, "You have been <green>reinvited</green> into my private channel "
|
||||
"after a bot restart or crash; Sorry for the inconvenience.")
|
||||
self.priv.invite(user)
|
||||
del self.reinvite
|
||||
|
||||
@staticmethod
|
||||
def load_private_channel_msg():
|
||||
with open("modules/core/private_channel/private_channel.msg", mode="r", encoding="utf-8") as f:
|
||||
return hjson.load(f)
|
||||
|
||||
def handle_incoming_relay_message(self, ctx):
|
||||
self.bot.send_private_channel_message(ctx.formatted_message, fire_outgoing_event=False)
|
||||
|
||||
@event(event_type="member_logon", description="Send autoinvites to players logging in")
|
||||
def logon_event(self, _, data):
|
||||
if not self.bot.is_ready():
|
||||
if data.packet.char_id not in self.reinvite:
|
||||
account = data.account
|
||||
if account.disabled == 1:
|
||||
pass
|
||||
elif account.auto_invite == 1:
|
||||
self.reinvite.append(data.packet.char_id)
|
||||
return
|
||||
if self.private_channel_service.in_private_channel(data.packet.char_id):
|
||||
return
|
||||
account = data.account
|
||||
if account.disabled == 1:
|
||||
return
|
||||
if self.db.query_single("SELECT * from org_bots where char_id=?", [data.packet.char_id]):
|
||||
return
|
||||
if account.auto_invite == 1:
|
||||
if self.pork.get_character_info(data.packet.char_id).org_id != self.bot.public_channel_service.org_id:
|
||||
self.private_channel_service.invite(data.packet.char_id)
|
||||
self.bot.send_mass_message(data.packet.char_id, "You have been "
|
||||
"<highlight>auto invited</highlight> "
|
||||
"into my private channel.")
|
||||
|
||||
@command(command="join", params=[], access_level="member",
|
||||
description="Join the private channel")
|
||||
def join_cmd(self, request):
|
||||
self.private_channel_service.invite(request.sender.char_id)
|
||||
|
||||
@command(command="leave", params=[], access_level="member",
|
||||
description="Leave the private channel")
|
||||
def leave_cmd(self, request):
|
||||
self.private_channel_service.kick(request.sender.char_id)
|
||||
|
||||
@command(command="invite", params=[Multiple(Character("character"))], access_level="member",
|
||||
description="Invite a character to the private channel")
|
||||
def invite_cmd(self, request, chars):
|
||||
success, in_channel, none, banned = [], [], [], []
|
||||
for char in chars:
|
||||
if char.char_id:
|
||||
if self.private_channel_service.in_private_channel(char.char_id):
|
||||
in_channel.append(char.name)
|
||||
elif self.ban_service.get_ban(char.char_id):
|
||||
banned.append(char.name)
|
||||
else:
|
||||
self.bot.send_private_message(char.char_id, self.getresp("module/private_channel",
|
||||
"invite_success_target",
|
||||
{"inviter": request.sender.name}))
|
||||
self.private_channel_service.invite(char.char_id)
|
||||
success.append(char.name)
|
||||
else:
|
||||
none.append(char.name)
|
||||
out = ""
|
||||
if len(in_channel) > 0:
|
||||
out += self.getresp("module/private_channel", "invite_fail", {"target": ", ".join(in_channel)}) + "\n"
|
||||
if len(success) > 0:
|
||||
out += self.getresp("module/private_channel", "invite_success_self", {"target": ", ".join(success)}) + "\n"
|
||||
if len(none) > 0:
|
||||
out += self.getresp("global", "char_not_found", {"char": ", ".join(none)}) + "\n"
|
||||
if len(banned) > 0:
|
||||
out += f'The Character <highlight>{", ".join(banned)}</highlight> is <red>banned</red>, ' \
|
||||
f'and cannot be invited.'
|
||||
if request.channel == "priv":
|
||||
return out.strip("\n")
|
||||
else:
|
||||
self.bot.send_mass_message(request.sender.char_id, out.strip("\n"))
|
||||
|
||||
@command(command="kick", params=[Character("character")], access_level="moderator",
|
||||
description="Kick a character from the private channel")
|
||||
def kick_cmd(self, request, char):
|
||||
if char.char_id:
|
||||
if not self.private_channel_service.in_private_channel(char.char_id):
|
||||
return self.getresp("module/private_channel", "kick_fail_not_in_priv", {"target": char.name})
|
||||
else:
|
||||
if self.access_service.has_sufficient_access_level(request.sender.char_id, char.char_id):
|
||||
self.bot.send_private_message(char.char_id, self.getresp("module/private_channel",
|
||||
"kick_success_target",
|
||||
{"kicker": request.sender.name}))
|
||||
self.private_channel_service.kick(char.char_id)
|
||||
return self.getresp("module/private_channel", "kick_success_self", {"target": char.name})
|
||||
else:
|
||||
return self.getresp("module/private_channel", "kick_fail", {"target": char.name})
|
||||
else:
|
||||
return self.getresp("global", "char_not_found", {"char": char.name})
|
||||
|
||||
@command(command="kickall", params=[], access_level="moderator",
|
||||
description="Kick all characters from the private channel")
|
||||
def kickall_cmd(self, request):
|
||||
self.bot.send_private_channel_message(self.getresp("module/private_channel", "kick_all",
|
||||
{"char": request.sender.name}))
|
||||
self.job_scheduler.delayed_job(lambda t: self.private_channel_service.kickall(), 10)
|
||||
|
||||
@event(event_type=BanService.BAN_ADDED_EVENT, description="Kick characters from the private channel who are banned",
|
||||
is_hidden=True)
|
||||
def ban_added_event(self, _, event_data):
|
||||
self.private_channel_service.kick(event_data.char_id)
|
||||
|
||||
@event(event_type=PrivateChannelService.PRIVATE_CHANNEL_MESSAGE_EVENT,
|
||||
description="Relay messages from the private channel to the relay hub", is_hidden=True)
|
||||
def handle_private_channel_message_event(self, _, event_data):
|
||||
if event_data.char_id == self.bot.get_char_id() or self.ban_service.get_ban(event_data.char_id):
|
||||
return
|
||||
|
||||
char_name = self.character_service.resolve_char_to_name(event_data.char_id)
|
||||
sender = DictObject({"char_id": event_data.char_id, "name": char_name})
|
||||
char = self.text.make_charlink(char_name)
|
||||
formatted_message = f"{self.PRIVATE_CHANNEL_PREFIX} {char}: {event_data.message}"
|
||||
self.message_hub_service.send_message(self.MESSAGE_SOURCE, sender, event_data.message, formatted_message)
|
||||
|
||||
@event(event_type=PrivateChannelService.JOINED_PRIVATE_CHANNEL_EVENT,
|
||||
description="Notify when a character joins the private channel")
|
||||
def handle_private_channel_joined_event(self, _, event_data):
|
||||
main = self.account_service.get_account(event_data.char_id)
|
||||
if main:
|
||||
info = "" if self.account_service.check_superadmin(main.char_id) else \
|
||||
":: <red>Admin</red> " if self.account_service.check_admin(main.char_id) else \
|
||||
":: <red>Moderator</red> " if self.account_service.check_moderator(main.char_id) else \
|
||||
":: <orange>Raidleader</orange> " if self.account_service.check_leader(main.char_id) else ""
|
||||
if main.char_id != event_data.char_id:
|
||||
info += f":: Alt of <{main.faction.lower()}>{main.name}</{main.faction.lower()}>"
|
||||
else:
|
||||
if self.setting_service.get_value('is_alliance_bot') == "0":
|
||||
info = ":: <red>WARN</red> » <notice>NO ACC</notice>"
|
||||
else:
|
||||
info = ""
|
||||
|
||||
msg = f"{self.text.format_char_info(self.pork.get_character_info(event_data.char_id))} joined us {info}"
|
||||
self.bot.send_private_channel_message(msg, fire_outgoing_event=False)
|
||||
self.message_hub_service.send_message(self.MESSAGE_SOURCE, None, msg, self.PRIVATE_CHANNEL_PREFIX + msg)
|
||||
od = OnlineDisplay(self.text, self.util, self.db)
|
||||
params = [self.bot.name, self.bot.get_char_id()]
|
||||
self.bot.send_mass_message(event_data.char_id,
|
||||
od.format_blob(od.format_by_channel_prof("and channel_id IN (1, 2) ", params)))
|
||||
|
||||
@event(event_type=PrivateChannelService.LEFT_PRIVATE_CHANNEL_EVENT,
|
||||
description="Notify when a character leaves the private channel")
|
||||
def handle_private_channel_left_event(self, _, event_data):
|
||||
char_info = self.pork.get_character_info(event_data.char_id)
|
||||
msg = f"<{char_info.faction.lower()}>{char_info.name}</{char_info.faction.lower()}> left us"
|
||||
self.bot.send_private_channel_message(msg, fire_outgoing_event=False)
|
||||
self.message_hub_service.send_message(self.MESSAGE_SOURCE, None, msg, msg)
|
||||
|
||||
@event(event_type=Tyrbot.OUTGOING_PRIVATE_CHANNEL_MESSAGE_EVENT,
|
||||
description="Relay commands from the private channel to the relay hub", is_hidden=True)
|
||||
def outgoing_private_channel_message_event(self, _, event_data):
|
||||
if isinstance(event_data.message, ChatBlob):
|
||||
pages = self.text.paginate(ChatBlob(event_data.message.title, event_data.message.msg),
|
||||
self.setting_service.get("org_channel_max_page_length").get_value())
|
||||
if len(pages) < 4:
|
||||
for page in pages:
|
||||
message = "{priv} {message}".format(priv=self.PRIVATE_CHANNEL_PREFIX, message=page)
|
||||
self.message_hub_service.send_message(self.MESSAGE_SOURCE,
|
||||
None,
|
||||
page,
|
||||
message)
|
||||
else:
|
||||
message = "{priv} {message}".format(priv=self.PRIVATE_CHANNEL_PREFIX, message=event_data.message.title)
|
||||
self.message_hub_service.send_message(self.MESSAGE_SOURCE,
|
||||
None,
|
||||
event_data.message.title,
|
||||
message)
|
||||
else:
|
||||
message = "{priv} {message}".format(priv=self.PRIVATE_CHANNEL_PREFIX, message=event_data.message)
|
||||
self.message_hub_service.send_message(self.MESSAGE_SOURCE,
|
||||
None,
|
||||
message,
|
||||
message)
|
||||
@@ -0,0 +1,75 @@
|
||||
import time
|
||||
|
||||
from core.command_param_types import Const, Any, Options
|
||||
from core.db import DB
|
||||
from core.decorators import instance, command, setting, event
|
||||
from core.dict_object import DictObject
|
||||
from core.private_channel_service import PrivateChannelService
|
||||
from core.setting_types import DictionarySettingType
|
||||
from core.text import Text
|
||||
|
||||
|
||||
@instance()
|
||||
class TopicController:
|
||||
def inject(self, registry):
|
||||
self.bot = registry.get_instance("bot")
|
||||
self.db: DB = registry.get_instance("db")
|
||||
self.text: Text = registry.get_instance("text")
|
||||
self.util = registry.get_instance("util")
|
||||
self.command_alias_service = registry.get_instance("command_alias_service")
|
||||
self.private_channel_service: PrivateChannelService = registry.get_instance("private_channel_service")
|
||||
|
||||
def start(self):
|
||||
self.command_alias_service.add_alias("motd", "topic")
|
||||
|
||||
@setting(name="topic", value="", description="The bot topic")
|
||||
def topic(self):
|
||||
return DictionarySettingType()
|
||||
|
||||
@command(command="topic", params=[], access_level="member",
|
||||
description="Show the current topic")
|
||||
def topic_show_command(self, request):
|
||||
topic = self.topic().get_value()
|
||||
if topic:
|
||||
return self.format_topic_message(topic)
|
||||
else:
|
||||
return "There is no current topic."
|
||||
|
||||
@command(command="topic", params=[Options(["clear", "unset"])], access_level="leader",
|
||||
description="Clears the current topic", sub_command="modify")
|
||||
def topic_clear_command(self, _, _1):
|
||||
self.topic().set_value("")
|
||||
|
||||
return "The topic has been cleared."
|
||||
|
||||
@command(command="topic",
|
||||
params=[Const("set", is_optional=True), Any("topic_message")],
|
||||
access_level="leader",
|
||||
description="Set the current topic", sub_command="modify")
|
||||
def topic_set_command(self, request, _, topic_message):
|
||||
sender = DictObject({"name": request.sender.name, "char_id": request.sender.char_id})
|
||||
|
||||
topic = {"topic_message": topic_message,
|
||||
"created_by": sender,
|
||||
"created_at": int(time.time())}
|
||||
|
||||
self.topic().set_value(topic)
|
||||
|
||||
return "The topic has been set."
|
||||
|
||||
def format_topic_message(self, topic):
|
||||
time_string = self.util.time_to_readable(int(time.time()) - topic["created_at"])
|
||||
return f"Topic: <highlight>{topic['topic_message']}<end> " \
|
||||
f"[set by <highlight>{topic['created_by']['name']}<end>][{time_string} ago]"
|
||||
|
||||
@event(PrivateChannelService.JOINED_PRIVATE_CHANNEL_EVENT, "Show topic to characters joining the private channel")
|
||||
def show_topic(self, _, event_data):
|
||||
topic = self.topic().get_value()
|
||||
if topic:
|
||||
self.bot.send_private_message(event_data.char_id, self.format_topic_message(topic))
|
||||
|
||||
@event(PrivateChannelService.LEFT_PRIVATE_CHANNEL_EVENT,
|
||||
"Clear topic when there are no characters in the private channel")
|
||||
def clear_topic(self, _, event_data):
|
||||
if self.topic().get_value() and len(self.private_channel_service.get_all_in_private_channel()) == 0:
|
||||
self.topic().set_value("")
|
||||
Reference in New Issue
Block a user