Skip to content

Commit 2b3d352

Browse files
authored
Create anope.tcl
Little script to add alias for anope services
1 parent 0fe640a commit 2b3d352

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

tcl/anope.tcl

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Copyright (c) 2024 by CrazyCat <[email protected]>
2+
#
3+
# This program is free software; you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License as published by
5+
# the Free Software Foundation; either version 3 of the License, or
6+
# (at your option) any later version.
7+
#
8+
# This program is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
# GNU General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU General Public License
14+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
#
16+
# ---------------------------------------------
17+
# Adds alias with autocompletion for Anope
18+
#
19+
# ---------------------------------------------
20+
# Think to change the chanserv setting in weechat
21+
# Option name: plugins.var.tcl.anope.<network>.chanserv
22+
# ---------------------------------------------
23+
# History
24+
# 2024-12-11 : Basic version: vop/hop/aop commands
25+
26+
set SCRIPT_VERSION 1.0
27+
set SCRIPT_NAME anope
28+
set SCRIPT_SUMMARY "Adds alias with autocompletion for Anope"
29+
30+
set CS_ARGS "vop|hop|aop <add|del> nick \[#channel\]"
31+
32+
set CS_ADESC "Alias for chanserv"
33+
34+
35+
::weechat::register $SCRIPT_NAME {CrazyCat <[email protected]>} $SCRIPT_VERSION GPL3 $SCRIPT_SUMMARY {} {}
36+
::weechat::hook_command cs $SCRIPT_SUMMARY $CS_ARGS $CS_ADESC {\
37+
vop add|del %(nicks) %(irc_server_channels)\
38+
|| hop add|del %(nicks) %(irc_server_channels)\
39+
|| aop add|del %(nicks) %(irc_server_channels)\
40+
} cs_op {}
41+
42+
array set SERVICES_NAMES {
43+
"chanserv" "ChanServ"
44+
"nickserv" "NickServ"
45+
"hostserv" "HostServ"
46+
}
47+
48+
array set SERVICES_DESC {
49+
"chanserv" "Channel management service name"
50+
"nickserv" "Channel management service name"
51+
"hostserv" "Channel management service name"
52+
}
53+
proc anope_setup {} {
54+
set slist [::weechat::infolist_get "irc_server" "" ""]
55+
while {[::weechat::infolist_next $slist]} {
56+
set server [::weechat::infolist_string $slist "name"]
57+
foreach service [array names ::SERVICES_NAMES] {
58+
if {![::weechat::config_is_set_plugin "${server}.${service}"]} {
59+
::weechat::config_set_plugin "${server}.${service}" $::SERVICES_NAMES($service)
60+
::weechat::config_set_desc_plugin "${server}.${service}" $::SERVICES_DESC($service)
61+
}
62+
}
63+
}
64+
::weechat::infolist_free $slist
65+
}
66+
67+
proc cs_op {data buffer args} {
68+
set btype [::weechat::buffer_get_string $buffer "localvar_type"]
69+
lassign {*}$args csact csflag nick channel
70+
switch $btype {
71+
channel {
72+
lassign [split [::weechat::buffer_get_string $buffer "localvar_name"] {.}] server channel
73+
}
74+
server {
75+
set server [::weechat::buffer_get_string $buffer "localvar_channel"]
76+
}
77+
default {
78+
::weechat::print $buffer "Sorry but you need to be in a server or a channel to use this command"
79+
return $::weechat::WEECHAT_RC_ERROR
80+
}
81+
}
82+
if {([string tolower $csflag] ni [list "add" "del"]) || ($nick eq "") || ($channel eq "")} {
83+
::weechat::print $buffer "Usage: /cs $::CS_ARGS"
84+
return $::weechat::WEECHAT_RC_ERROR
85+
}
86+
::weechat::command $server "/msg [::weechat::config_get_plugin "${server}.chanserv"] $csact $channel $csflag $nick"
87+
88+
return $::weechat::WEECHAT_RC_OK
89+
}
90+
91+
anope_setup

0 commit comments

Comments
 (0)