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

report channel counts and modes in status #1562

Merged
merged 2 commits into from
Oct 5, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 45 additions & 7 deletions plugins/Status/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,53 @@ def status(self, irc, msg, args):

Returns the status of the bot.
"""
networks = {}
# Initialize dictionaries
nicks = {}
channel_counts = {}
op_counts = {}
halfop_counts = {}
voice_counts = {}
normal_counts = {}

# Iterate through each IRC network
for Irc in world.ircs:
networks.setdefault(Irc.network, []).append(Irc.nick)
networks = sorted(networks.items())
networks = [format(_('%s as %L'), net, nicks) for (net,nicks) in networks]
L = [format(_('I am connected to %L.'), networks)]
network_name = Irc.network
channels = Irc.state.channels

# Initialize counts for this network
channel_counts[network_name] = 0
op_counts[network_name] = 0
halfop_counts[network_name] = 0
voice_counts[network_name] = 0
normal_counts[network_name] = 0
nicks[network_name] = Irc.nick

# Iterate through channels in this network
for channel, channelinfo in channels.items():
# Increment the channel count for this network
channel_counts[network_name] += 1
if Irc.nick in channelinfo.ops:
op_counts[network_name] += 1
elif Irc.nick in channelinfo.halfops:
halfop_counts[network_name] += 1
elif Irc.nick in channelinfo.voices:
voice_counts[network_name] += 1
elif Irc.nick in channelinfo.users:
normal_counts[network_name] += 1

# Prepare the response
response_lines = []
for network_name in channel_counts:
response_lines.append(
f"I am connected to {network_name} as {nicks[network_name]}, Channels: {channel_counts[network_name]}, "
f"Ops: {op_counts[network_name]}, Half-Ops: {halfop_counts[network_name]}, "
f"Voiced: {voice_counts[network_name]}, Regular: {normal_counts[network_name]} "
)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep the _() wrapper and %s substitution so it's translatable.


irc.reply("".join(response_lines))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep %L formatting so items are joined according to the config and locale


if world.profiling:
L.append(_('I am currently in code profiling mode.'))
irc.reply(' '.join(L))
irc.reply(_('I am currently in code profiling mode.'))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And keep this in the list, so it does not send it as an independent message

status = wrap(status)

@internationalizeDocstring
Expand Down
Loading