async def command(chat_attrs: ChatAttribute, args: List): if not args: await quick_reply(chat_attrs, 'Empty keyword list') return False old_keywords = set(self.config.Keyword) new_keywords = set(args) exists_keywords = old_keywords & new_keywords added_keywords = new_keywords - exists_keywords if added_keywords: self.config.Keyword = list(old_keywords | new_keywords) UMRConfig.save_config() if exists_keywords: await quick_reply( chat_attrs, f'Success, added keywords: {", ".join(added_keywords)}\n' f'exists keywords: {", ".join(exists_keywords)}') await quick_reply( chat_attrs, f'Success, added keywords: {", ".join(added_keywords)}') else: await quick_reply( chat_attrs, f'All keyword exists: {", ".join(exists_keywords)}')
async def command(chat_attrs: ChatAttribute, args: List): if not chat_attrs.reply_to: await quick_reply( chat_attrs, 'Message not specified, please reply to a message') return False reply_chat_attrs = chat_attrs.reply_to if not reply_chat_attrs.forward_from: # definitely not a channel await quick_reply(chat_attrs, 'Message is not a forward') return False if reply_chat_attrs.forward_from.chat_id >= 0: await quick_reply(chat_attrs, 'Message is not from channel') return False channel_id = reply_chat_attrs.forward_from.chat_id if channel_id in self.config.ChatID: await quick_reply(chat_attrs, 'Channel already exists') else: self.config.ChatID.append( reply_chat_attrs.forward_from.chat_id) UMRConfig.save_config() await quick_reply( chat_attrs, f'Success, added channel {reply_chat_attrs.forward_from.name}' )
39: '[赞]', 40: '[眨眼]' } class MiraiDriverConfig(UMRConfig.BaseDriverConfig): Base: Literal['Mirai'] Account: int Host: str Port: int = Field(18080, ge=0, le=65535) AuthKey: str NameforPrivateChat: bool = True NameforGroupChat: bool = True UMRConfig.register_driver_config(MiraiDriverConfig) class MiraiDriver(BaseDriverMixin): def __init__(self, name): super().__init__(name) self.name = name self.logger = UMRLogging.get_logger('Mirai') self.loop: asyncio.AbstractEventLoop = asyncio.new_event_loop() self.loop.set_exception_handler(self.handle_exception) self.image_cache = dict() self.config: MiraiDriverConfig = UMRConfig.config.Driver[self.name] self.qq = self.config.Account
from PIL import ImageFile class LineDriverConfig(UMRConfig.BaseDriverConfig): Base: Literal['Line'] ChannelID: str BotToken: str WebHookToken: str WebHookURL: str WebHookPort: int = Field(28080, ge=0, le=65535) HTTPSCert: str HTTPSKey: str HTTPSCA: str UMRConfig.register_driver_config(LineDriverConfig) class LineDriver(UMRDriver.BaseDriverMixin): def __init__(self, name): super().__init__(name) self.name = name self.logger = UMRLogging.get_logger(f'UMRDriver.{self.name}') self.logger.debug(f'Started initialization for {self.name}') self.loop: asyncio.AbstractEventLoop = asyncio.new_event_loop() self.loop.set_exception_handler(self.handle_exception) self.config: LineDriverConfig = UMRConfig.config.Driver[self.name] self.handler: WebhookHandlerAsync self.user_names: Dict[str, str] = dict() # [user_id, username]
from aiogram.types import ContentType from unified_message_relay.Core.UMRType import UnifiedMessage, MessageEntity, ChatAttribute, ChatType, EntityType from unified_message_relay.Core import UMRDriver from unified_message_relay.Core import UMRLogging from unified_message_relay.Core import UMRConfig from unified_message_relay.Core.UMRMessageRelation import set_ingress_message_id, set_egress_message_id from unified_message_relay.Util.Helper import unparse_entities_to_html class TelegramDriverConfig(UMRConfig.BaseDriverConfig): Base: Literal['Telegram'] BotToken: str HTTPProxy: Optional[str] UMRConfig.register_driver_config(TelegramDriverConfig) class TelegramDriver(UMRDriver.BaseDriverMixin): def __init__(self, name): super().__init__(name) self.name = name # Initialize bot and dispatcher self.logger = UMRLogging.get_logger(f'UMRDriver.{self.name}') self.logger.debug(f'Started initialization for {self.name}') self.config: TelegramDriverConfig = UMRConfig.config.Driver[self.name] self.bot_user_id = int(self.config.BotToken.split(':')[0]) self.image_file_id: Dict[
class QQDriverConfig(UMRConfig.BaseDriverConfig): Base: Literal['QQ'] Account: int APIRoot: str ListenIP: str ListenPort: int = Field(8080, ge=0, le=65535) Token: str Secret: str IsPro: bool = False NameforPrivateChat: bool = True NameforGroupChat = True UMRConfig.register_driver_config(QQDriverConfig) class QQDriver(UMRDriver.BaseDriverMixin): def __init__(self, name): super().__init__(name) self.name = name self.logger = UMRLogging.get_logger(f'UMRDriver.{self.name}') self.logger.debug(f'Started initialization for {self.name}') self.loop: asyncio.AbstractEventLoop = asyncio.new_event_loop() self.loop.set_exception_handler(self.handle_exception) self.config: QQDriverConfig = UMRConfig.config.Driver[self.name] self.bot = CQHttp(api_root=self.config.APIRoot,
entity_type=entity_type) entity_list.append(message_entity) real_start = real_start + len(delta) result += delta entity_list.extend(_entity_list) text_start = outer_end class DiscordDriverConfig(UMRConfig.BaseDriverConfig): Base: Literal['Discord'] BotToken: str ClientToken: str UMRConfig.register_driver_config(DiscordDriverConfig) class DiscordDriver(UMRDriver.BaseDriverMixin, discord.Client): def __init__(self, name: str): self.loop = asyncio.new_event_loop() self.loop.set_exception_handler(self.handle_exception) discord.Client.__init__(self, loop=self.loop) self.name = name self.logger = UMRLogging.get_logger(self.name) self.config: DiscordDriverConfig = UMRConfig.config.Driver[self.name] def start(self): def run():
from unified_message_relay.Core.UMRExtension import BaseExtension, register_extension from unified_message_relay.Core import UMRConfig logger = UMRLogging.get_logger('Plugin.WaterMeter') # Telegram water meter filter # supports keyword filter, forward source filter(chat id based) class TelegramWaterMeterConfig(UMRConfig.BaseExtensionConfig): Extension: Literal['TelegramWaterMeter'] Keyword: Optional[List[str]] ChatID: Optional[List[int]] UMRConfig.register_extension_config(TelegramWaterMeterConfig) class TelegramWaterMeter(BaseExtension): def __init__(self): super().__init__() async def post_init(self): await super().post_init() self.config: TelegramWaterMeterConfig = \ UMRConfig.config.ExtensionConfig.setdefault(__name__, TelegramWaterMeterConfig( Extension='TelegramWaterMeter', Keyword=[], ChatID=[]))