Skip to content

Commit 5ccc035

Browse files
authored
report channel counts and modes in status (#1562)
1 parent 5828720 commit 5ccc035

File tree

1 file changed

+43
-7
lines changed

1 file changed

+43
-7
lines changed

plugins/Status/plugin.py

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,53 @@ def status(self, irc, msg, args):
7676
7777
Returns the status of the bot.
7878
"""
79+
# Initialize dictionaries
80+
nicks = {}
7981
networks = {}
82+
# Iterate through each IRC network
8083
for Irc in world.ircs:
81-
networks.setdefault(Irc.network, []).append(Irc.nick)
82-
networks = sorted(networks.items())
83-
networks = [format(_('%s as %L'), net, nicks) for (net,nicks) in networks]
84-
L = [format(_('I am connected to %L.'), networks)]
84+
network_name = Irc.network
85+
channels = Irc.state.channels
86+
87+
# Initialize counts for this network
88+
channel_counts = len(channels)
89+
op_counts = sum(1 for channel in channels.values() if Irc.nick in channel.ops)
90+
halfop_counts = sum(1 for channel in channels.values() if Irc.nick in channel.halfops)
91+
voice_counts = sum(1 for channel in channels.values() if Irc.nick in channel.voices)
92+
normal_counts = sum(1 for channel in channels.values() if Irc.nick in channel.users)
93+
94+
# Store the counts in dictionaries
95+
nicks[network_name] = Irc.nick
96+
networks[network_name] = {
97+
'Channels': channel_counts,
98+
'Ops': op_counts,
99+
'Half-Ops': halfop_counts,
100+
'Voiced': voice_counts,
101+
'Regular': normal_counts
102+
}
103+
104+
# Prepare the response
105+
response_lines = []
106+
for network_name, counts in networks.items():
107+
response_lines.append(
108+
format(
109+
_('I am connected to %s as %s: Channels: %s, Ops: %s, Half-Ops: %s, Voiced: %s, Regular: %s'),
110+
network_name,
111+
nicks[network_name],
112+
counts['Channels'],
113+
counts['Ops'],
114+
counts['Half-Ops'],
115+
counts['Voiced'],
116+
counts['Regular']
117+
)
118+
)
119+
85120
if world.profiling:
86-
L.append(_('I am currently in code profiling mode.'))
87-
irc.reply(' '.join(L))
121+
response_lines.append(_('I am currently in code profiling mode.'))
122+
response = format(_("%L"), response_lines)
123+
irc.reply(response)
88124
status = wrap(status)
89-
125+
90126
@internationalizeDocstring
91127
def threads(self, irc, msg, args):
92128
"""takes no arguments

0 commit comments

Comments
 (0)