Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(irc): setting to add a postfix to nicknames for all IRC puppets #89

Merged
merged 1 commit into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ Options:
'#'. [required]
--irc-puppet-ip-range TEXT An IPv6 CIDR range to use for IRC puppets.
(2001:A:B:C:D::/80)
--irc-puppet-postfix TEXT Postfix to add to IRC puppet nicknames
(default: none).
--irc-ignore-list TEXT IRC nicknames to not relay messages for (comma
separated, case-insensitive).
--irc-idle_timeout INTEGER IRC puppet idle timeout, in seconds (default:
Expand Down
13 changes: 12 additions & 1 deletion dibridge/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
@click.option("--irc-nick", help="IRC nick to use.", required=True)
@click.option("--irc-channel", help="IRC channel to relay to, without the first '#'.", required=True)
@click.option("--irc-puppet-ip-range", help="An IPv6 CIDR range to use for IRC puppets. (2001:A:B:C:D::/80)")
@click.option("--irc-puppet-postfix", help="Postfix to add to IRC puppet nicknames (default: none).", default="")
@click.option("--irc-ignore-list", help="IRC nicknames to not relay messages for (comma separated, case-insensitive).")
@click.option(
"--irc-idle-timeout",
Expand All @@ -38,6 +39,7 @@ def main(
irc_nick,
irc_channel,
irc_puppet_ip_range,
irc_puppet_postfix,
irc_ignore_list,
irc_idle_timeout,
):
Expand All @@ -54,7 +56,16 @@ def main(
thread_d = threading.Thread(target=discord.start, args=[discord_token, discord_channel_id])
thread_i = threading.Thread(
target=irc.start,
args=[irc_host, irc_port, irc_nick, f"#{irc_channel}", irc_puppet_ip_range, irc_ignore_list, irc_idle_timeout],
args=[
irc_host,
irc_port,
irc_nick,
f"#{irc_channel}",
irc_puppet_ip_range,
irc_puppet_postfix,
irc_ignore_list,
irc_idle_timeout,
],
)

thread_d.start()
Expand Down
9 changes: 5 additions & 4 deletions dibridge/irc.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


class IRCRelay(irc.client_aio.AioSimpleIRCClient):
def __init__(self, host, port, nickname, channel, puppet_ip_range, ignore_list, idle_timeout):
def __init__(self, host, port, nickname, channel, puppet_ip_range, puppet_postfix, ignore_list, idle_timeout):
irc.client.SimpleIRCClient.__init__(self)

self._loop = asyncio.get_event_loop()
Expand All @@ -33,6 +33,7 @@ def __init__(self, host, port, nickname, channel, puppet_ip_range, ignore_list,
self._tell_once = True
self._channel = channel
self._puppet_ip_range = puppet_ip_range
self._puppet_postfix = puppet_postfix
self._pinger_task = None
self._ignore_list = ignore_list
self._idle_timeout = idle_timeout
Expand Down Expand Up @@ -159,7 +160,7 @@ async def _send_message(self, discord_id, discord_username, message, is_action=F
self._host,
self._port,
ipv6_address,
sanitized_discord_username,
f"{sanitized_discord_username}{self._puppet_postfix}",
self._channel,
functools.partial(self._remove_puppet, discord_id),
self._idle_timeout,
Expand Down Expand Up @@ -276,10 +277,10 @@ def stop(self):
asyncio.run_coroutine_threadsafe(self._stop(), self._loop)


def start(host, port, name, channel, puppet_ip_range, ignore_list, idle_timeout):
def start(host, port, name, channel, puppet_ip_range, puppet_postfix, ignore_list, idle_timeout):
asyncio.set_event_loop(asyncio.new_event_loop())

relay.IRC = IRCRelay(host, port, name, channel, puppet_ip_range, ignore_list, idle_timeout)
relay.IRC = IRCRelay(host, port, name, channel, puppet_ip_range, puppet_postfix, ignore_list, idle_timeout)

log.info("Connecting to IRC ...")
asyncio.get_event_loop().run_until_complete(relay.IRC._connect())
Expand Down