Record channel admins in Telegram as ops in IRC, and channel creators in Telegram as creators/founders in IRC
patch 5c06638983343c88cd73232a723f5efa09fed082
Author: E. Bosch <presidev@AT@gmail.com>
Date: Mon Feb 1 23:18:25 CET 2021
* Record channel admins in Telegram as ops in IRC, and channel creators in Telegram as creators/founders in IRC
diff -rN -u old-irgramd/irc.py new-irgramd/irc.py
--- old-irgramd/irc.py 2024-10-23 06:29:34.219633909 +0200
+++ new-irgramd/irc.py 2024-10-23 06:29:34.219633909 +0200
@@ -94,6 +94,8 @@
)
self.iid_to_tid = {}
self.irc_channels = collections.defaultdict(set)
+ self.irc_channels_ops = collections.defaultdict(set)
+ self.irc_channels_founder = {}
self.start_time = time.strftime('%a %d %b %Y %H:%M:%S %z')
@@ -198,7 +200,8 @@
await self.reply_code(user, 'RPL_ENDOFMOTD')
async def join_irc_channel(self, user, channel, full_join=False):
- self.irc_channels[channel.lower()].add(user.irc_nick)
+ chan = channel.lower()
+ self.irc_channels[chan].add(user.irc_nick)
# Join Channel
await self.send_irc_command(user, ':{} JOIN :{}'.format(
diff -rN -u old-irgramd/telegram.py new-irgramd/telegram.py
--- old-irgramd/telegram.py 2024-10-23 06:29:34.219633909 +0200
+++ new-irgramd/telegram.py 2024-10-23 06:29:34.219633909 +0200
@@ -2,6 +2,7 @@
import logging
import os
import telethon
+from telethon import types as tgty
# Local modules
@@ -65,7 +66,7 @@
# Update IRC <-> Telegram mapping
async for dialog in self.telegram_client.iter_dialogs():
chat = dialog.entity
- if isinstance(chat, telethon.types.User):
+ if isinstance(chat, tgty.User):
if not chat.is_self:
self.set_ircuser_from_telegram(chat)
else:
@@ -86,10 +87,18 @@
channel = self.get_telegram_channel(chat)
self.tid_to_iid[chat.id] = channel
self.irc.iid_to_tid[channel.lower()] = chat.id
+ chan = channel.lower()
# Add users from the channel
- for user in [x async for x in self.telegram_client.iter_participants(chat.id) if not x.is_self]:
+ async for user in self.telegram_client.iter_participants(chat.id):
user_nick = self.set_ircuser_from_telegram(user)
- self.irc.irc_channels[channel.lower()].add(user_nick)
+ if not user.is_self:
+ self.irc.irc_channels[chan].add(user_nick)
+ # Add admin users as ops in irc
+ if isinstance(user.participant, tgty.ChatParticipantAdmin):
+ self.irc.irc_channels_ops[chan].add(user_nick)
+ # Add creator users as founders in irc
+ elif isinstance(user.participant, tgty.ChatParticipantCreator):
+ self.irc.irc_channels_founder[chan] = user_nick
def get_telegram_nick(self, user):
nick = (user.username
@@ -216,7 +225,7 @@
async def join_all_telegram_channels(self):
async for dialog in self.telegram_client.iter_dialogs():
chat = dialog.entity
- if not isinstance(chat, telethon.types.User):
+ if not isinstance(chat, tgty.User):
channel = self.get_telegram_channel(chat)
self.tid_to_iid[chat.id] = channel
self.irc.iid_to_tid[channel] = chat.id