Added afk/brb

Timer messages ("Timer XX has yyy left") now get resumed after a bot restart
Alliance relay is discord compatible now. [Orgbot]
This commit is contained in:
2021-10-26 22:35:31 +02:00
parent bd8055dac7
commit 2d7ecf4883
14 changed files with 119 additions and 48 deletions
+45 -2
View File
@@ -1,3 +1,4 @@
import re
import time
from threading import Thread
@@ -7,13 +8,17 @@ from core.command_alias_service import CommandAliasService
from core.command_param_types import Int, Any, Const, Options
from core.db import DB
from core.decorators import instance, event, command
from core.dict_object import DictObject
from core.fifo_queue import FifoQueue
from core.logger import Logger
from core.lookup.character_service import CharacterService
from core.private_channel_service import PrivateChannelService
from core.public_channel_service import PublicChannelService
from core.setting_service import SettingService
from core.text import Text
from core.igncore import IgnCore
from core.util import Util
from modules.core.accounting.services.account_service import AccountService
from modules.standard.online.online_display import OnlineDisplay
@@ -26,7 +31,8 @@ class User:
@instance()
class OnlineController:
def __init__(self):
self.assist = []
self.afk_list = {}
self.afk_regex = re.compile("^(afk|brb) ?(.*)$", re.IGNORECASE)
self.awaiting_data = FifoQueue()
def inject(self, registry):
@@ -39,7 +45,9 @@ class OnlineController:
self.buddy_service: BuddyService = registry.get_instance("buddy_service")
self.setting_service: SettingService = registry.get_instance("setting_service")
self.priv: PrivateChannelService = registry.get_instance("private_channel_service")
self.online_display: OnlineDisplay = OnlineDisplay(self.text, self.util, self.db)
self.online_display: OnlineDisplay = OnlineDisplay(self.text, self.util, self.db, self.afk_list)
self.account_service: AccountService = registry.get_instance("account_service")
self.character_service: CharacterService = registry.get_instance("character_service")
def pre_start(self):
self.db.exec("DROP TABLE IF EXISTS online")
@@ -67,6 +75,8 @@ class OnlineController:
def priv_leave(self, _, event_data):
self.db.exec("delete from online where char_id = ? and bot = ? and channel=?",
[event_data.char_id, self.bot.get_char_id(), self.bot.name])
for alt in self.account_service.get_alts(event_data.char_id):
self.afk_list.pop(alt.char_id, None)
@event(event_type="member_logon", description="declare players as online")
def logon(self, _, event_data):
@@ -90,6 +100,8 @@ class OnlineController:
self.db.exec("DELETE FROM online where char_id=? and bot=?",
[data.packet.char_id, self.bot.get_char_id()])
self.db.exec("UPDATE account set last_seen=? where char_id=?", [time.time(), data.packet.char_id])
for alt in self.account_service.get_alts(data.packet.char_id):
self.afk_list.pop(alt.char_id, None)
@command(command="online", params=[Const('all', is_optional=True),
Int("min_level", is_optional=True),
@@ -134,3 +146,34 @@ class OnlineController:
return f"Invalid Title level: {filters}"
output = self.online_display.count_tl(query, params, filters)
return output if output != "" else "Nobody is in my private channel, sorry..."
@event(PrivateChannelService.PRIVATE_CHANNEL_MESSAGE_EVENT, "Check for afk messages in private channel")
def afk_check_private_channel_event(self, event_type, event_data):
self.afk_check(event_data.char_id, event_data.message, lambda msg: self.bot.send_private_channel_message(msg))
@event(PublicChannelService.ORG_CHANNEL_MESSAGE_EVENT, "Check for afk messages in org channel")
def afk_check_org_channel_event(self, event_type, event_data):
self.afk_check(event_data.char_id, event_data.message, lambda msg: self.bot.send_org_message(msg))
def afk_check(self, char_id, message, channel_reply):
matches = self.afk_regex.search(message)
if matches:
char_name = self.character_service.resolve_char_to_name(char_id)
channel_reply(f"<highlight>{char_name}</highlight> is now afk.")
alts = self.account_service.get_alts(char_id)
for alt in alts:
self.afk_list[alt.char_id] = DictObject({"message": message, "time": time.time()})
elif char_id in self.afk_list.keys():
# TODO handle multiple rows
alts = self.account_service.get_alts(char_id)
data = None
for alt in alts:
out = self.afk_list.pop(alt.char_id)
if data:
continue
data = out
char_name = self.character_service.resolve_char_to_name(char_id)
time_string = self.util.time_to_readable(int(time.time()) - data.time)
channel_reply(f"<highlight>{char_name}</highlight> is back after {time_string}.")