File: listidle

package info (click to toggle)
ircii 20190117-1%2Bdeb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 5,788 kB
  • sloc: ansic: 44,172; makefile: 863; sh: 524; perl: 291
file content (181 lines) | stat: -rw-r--r-- 5,187 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#	$eterna: listidle,v 1.5 2006/07/26 02:05:45 mrg Exp $
#
# tristan+irc@ethereal.net 31jul2000, 2jul2001, 24jul2006
#
# bugs/lacking features:
# - only works correctly on servers that support multiple-nick /whois (as
#   of this writing, most of EFnet does not) -- this could be automatically
#   detected and worked around
# - only works on current channel
# - /listidle will eat all whois replies until it's done (so among other
#   things, you can't use /whois while it's running)

# for $notword(), $lformat(), $format(), $sort()
load functions

if (max_recursions < 100) {
  # li.fixsend uses recursion, unfortunately
  set max_recursions 100
}

if (novice == [ON]) {
  # we need this for ON to work
  set novice off
}

alias li.fixsend {
  # Input: nick1[!user@host] [nick2[!user@host] ...]
  # Output: nick1,nick2,...
  if ([$1]) {
    @ function_return = [$left($index(! $0) $0),$li.fixsend($1-)]
  }
  {
    @ function_return = [$left($index(! $0) $0)]
  }
}

alias listidle {
  if (left(2 $0) == [-s]) {
    @ LI.SORTED = 1
  }
  whois $li.fixsend($chanusers($C))
  ^on ^raw_irc "% 311 *" {
    @ LI.USERHOST[$encode($3)] = [$4@$5]
  }
  ^on ^raw_irc "% 319 *" #might want to do something here (channels)
  ^on ^raw_irc "% 313 *" #might want to do something here (IRCop)
  ^on ^raw_irc "% 320 *" #might want to do something here ("identified to services")
  ^on ^raw_irc "% 301 *" {
    @ LI.AWAY[$encode($3)] = [ (aw)]
  }
  ^on ^raw_irc "% 317 *" {
    @ LI.IDLE[$encode($3)] = [$4]
    @ LI.SIGNON[$encode($3)] = [$5]
  }
  ^on ^raw_irc "% 312 *" {
    if ([$0]!=[$4]) {
      @ LI.SERVERS[$encode($4)] = LI.SERVERS[$encode($4)] ## [ $3]
    }
  }
  ^on ^raw_irc "% 318 *" {
    ^on raw_irc -"% 311 *"
    ^on raw_irc -"% 319 *"
    ^on raw_irc -"% 313 *"
    ^on raw_irc -"% 320 *"
    ^on raw_irc -"% 301 *"
    ^on raw_irc -"% 317 *"
    ^on raw_irc -"% 312 *"
    ^on raw_irc -"% 318 *"
    li.rwhois
  }
}

alias li.rwhois {
  @ LI.COUNT = 0
  foreach li.servers serv {
    whois $decode($serv) $li.fixsend($li.servers[$serv])
    @ LI.COUNT = LI.COUNT + 1
    ^assign -li.servers.$serv
  }
  ^assign -serv
  ^on ^raw_irc "% 311 *" #
  ^on ^raw_irc "% 319 *" #might want to do something here (channels)
  ^on ^raw_irc "% 313 *" #might want to do something here (IRCop)
  ^on ^raw_irc "% 320 *" #might want to do something here ("identified to services")
  ^on ^raw_irc "% 301 *" {
    @ LI.AWAY[$encode($3)] = [ (aw)]
  }
  ^on ^raw_irc "% 317 *" {
    @ LI.IDLE[$encode($3)] = [$4]
    @ LI.SIGNON[$encode($3)] = [$5]
  }
  ^on ^raw_irc "% 312 *" #
  ^on ^raw_irc "% 318 *" {
    @ LI.COUNT = LI.COUNT - 1
    if (!LI.COUNT) {
      ^on raw_irc -"% 311 *"
      ^on raw_irc -"% 319 *"
      ^on raw_irc -"% 313 *"
      ^on raw_irc -"% 320 *"
      ^on raw_irc -"% 301 *"
      ^on raw_irc -"% 317 *"
      ^on raw_irc -"% 312 *"
      ^on raw_irc -"% 318 *"
      if (li.sorted) {
        li.sortedlist
      } {
        li.list
      }
      ^assign -li.sorted
    }
  }
}

alias li.vaguetdiff {
  # This function reduces precision of tdiff a bit when tdiff is large.
  @ li.args = [$*]
  if ([$[6]word(${#li.args-1} $*)] == [second] && #li.args != 2) {
    @ li.args = notword(${#li.args-1} $notword($#li.args $*))
  }
  if (#li.args > 3) {
    @ function_return = [$word(0 $li.args) $word(1 $li.args) $word(2 $li.args) $word(3 $li.args)]
  } {
    @ function_return = [$word(0 $li.args) $word(1 $li.args)]
  }
  ^assign -li.args
}

alias li.abbrtdiff {
  # This function abbreviates hours to h, minutes to m, etc.
  if ([$2]) {
    @ function_return = [$0$left(1 $1)$li.abbrtdiff($2-)]
  }
  {
    @ function_return = [$0$left(1 $1)]
  }
}

alias li.list {
  echo ***  Nickname        Idle Sign-On      Account
  foreach li.idle li.nick {
    echo ***  $lformat(9 $decode($li.nick)) $format(10 $li.abbrtdiff($li.vaguetdiff($tdiff($li.idle[$li.nick])))) $strftime($li.signon[$li.nick] %b %e %H:%M) $li.userhost[$li.nick]$li.away[$li.nick]
    ^assign -li.idle[$li.nick]
    ^assign -li.signon[$li.nick]
    ^assign -li.userhost[$li.nick]
    ^assign -li.away[$li.nick]
  }
  ^assign -li.nick
}

alias li.sortedlist {
  @ li.curtime = time()
  foreach li.idle nick {
    @ li.since = li.curtime - li.idle[$nick]
    while (@li.zeroes < 10 - @li.since) {
      @ li.zeroes = li.zeroes ## [0]
    }
    @ li.tosort = [$encode($li.zeroes$li.since).$nick ] ## li.tosort
    ^assign -li.zeroes
  }
  @ li.sorted = sort($li.tosort)
  @ li.count = 0
  echo ***  Nickname        Idle Sign-On      Account
  while (word($li.count $li.sorted)) {
    @ li.code = word($li.count $li.sorted)
    @ li.nick = mid(21 999 $li.code)
    echo ***  $lformat(9 $decode($li.nick)) $format(10 $li.abbrtdiff($li.vaguetdiff($tdiff(${li.curtime - decode($left(20 $li.code))})))) $strftime($li.signon[$li.nick] %b %e %H:%M) $li.userhost[$li.nick]$li.away[$li.nick]
    ^assign -li.idle[$li.nick]
    ^assign -li.signon[$li.nick]
    ^assign -li.userhost[$li.nick]
    ^assign -li.away[$li.nick]
    @ li.count = li.count + 1
  }
  ^assign -li.sorted
  ^assign -li.tosort
  ^assign -li.curtime
  ^assign -li.count
  ^assign -li.code
  ^assign -li.since
  ^assign -li.nick
  ^assign -li.diff
}