-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMediaWikiLinks.tcl
166 lines (145 loc) · 7.31 KB
/
MediaWikiLinks.tcl
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
namespace eval ::MW {
##################################################
# Operator873's MediaWiki Link Generator #
##################################################
# I hold no rights to the following script and #
# release it to the general public to be used, #
# re-written in part or in whole, or shared so #
# long as this original header is included as is.#
# #
# #
##################################################
##################################################
# CONFIGURATION AND SETTINGS #
##################################################
# Example link: https://subdomain.example.com/Article
# Example link: https://subdomain.example.com/Project:Page
# Example command: !link <projecet> <article name>
# Example command: !link <article name>
# Set your domain name
#
# Set the main domain of your MediaWiki install.
# This script will assume https is always used.
# (Ex: "example.com")
variable domain "example.com"
# Set your "Languages"
#
# MediaWiki installs typically utilize subdomains to separate projects or languages.
# (ex: en.wikipedia.org, es.wikipedia.org, etc)
# List the language abreviations separated by spaces. If included after !link, the
# script will override the default 'language' (set below) and replace it with this one.
# Instead of https://default.example.com, the link would be https://lang.example.com
# (from above examples: "en es")
variable lang "subdomain1 subdomain2 subdomain3"
# Set your default "Language"
#
# If no "language" is specified or language is not detected,
# what "language" should be used as the default?
# !link Some Artile --> https://default.example.com
variable def "default"
# Excluded channels
#
# List any channels here that the bot should never answer in commands
# Separate channels with spaces
# variable exchan "#thisChannel #thatChannel"
variable exchan ""
#########################
# Bot Commands #
#########################
# Anatomy of below commands
#
# bind - assigns the command. Don't change.
# pub/pubm/msg
# pub indicates the command is the first word. EX: !link Some Page
# pubm indicates the command can occur anywhere in a message. EX: Hey! read this: !link Some Page
# msg indicates the command will be sent to the bot via /msg botnick !link Some Page. Problematic if used.
# -/f/l/o/n - can be global or global | channel (Ex: f|o)
# - No restriction on who can use the command
# f Bot will only respond to nicks that are added to the Eggdrop user file with .chattr <Nick> +f
# l Bot will only respond to nicks that are added to the Eggdrop user file with .chattr <Nick> +l
# o Bot will only respond to nicks that are added to the Eggdrop user file with .chattr <Nick> +o
# n Bot will only respond to the nick that is the owner of the bot.
# f|o will match anyone in the user file with +f OR a channel op in the channel the command occurs in
# "command"
# The exact command that will trigger the bot's function. It's strongly recommended to use a special character # Procedure
# This is the procedure call for the bind. Generally, you should NOT change them.
bind pub - "'link" ::MW::Link
bind pub f "'contribs" ::MW::Contribs
bind pub l "'block" ::MW::Block
bind pub f "'ipintel" ::MW::ipintel
bind pub f "'urban" ::MW::udc
bind pub f "'google" ::MW::Google
bind pub f "'log" ::MW::Log
}
#####################################
# Below is the coding. #
# If you edit this, and don't know #
# what you're doing, you can break #
# the script. #
#####################################
proc ::MW::Link {nick host hand chan text} {
set text [split $text]
set project [lindex $text 0]
if {[lsearch -nocase $::MW::lang $project] >= 0 && [lsearch -nocase $::MW::exchan $chan] < 0} {
set linkstring [string map {{ } {_}} [lrange $text 1 end]]
putserv "PRIVMSG $chan :https://$project.$::MW::domain/wiki/$linkstring"
} elseif {[lsearch -nocase $::MW::exchan $chan] < 0} {
set linkstring [string map {{ } {_}} [lrange $text 0 end]]
putserv "PRIVMSG $chan :https://$::MW::def.$::MW::domain/wiki/$linkstring"
}
}
proc ::MW::Contribs {nick host hand chan text} {
set text [split $text]
set project [lindex $text 0]
if {[lsearch -nocase $::MW::lang $project] >= 0 && [lsearch -nocase $::MW::exchan $chan] < 0} {
set target [string map {{ } {_}} [lrange $text 1 end]]
putserv "PRIVMSG $chan :https://$project.$::MW::domain/wiki/Special:Contributions/$target"
} elseif {[lsearch -nocase $::MW::exchan $chan] < 0} {
set target [string map {{ } {_}} [lrange $text 0 end]]
putserv "PRIVMSG $chan :https://$::MW::def.$::MW::domain/wiki/Special:Contributions/$target"
}
}
proc ::MW::Block {nick host hand chan text} {
set text [split $text]
set project [lindex $text 0]
if {[lsearch -nocase $::MW::lang $project] >= 0 && [lsearch -nocase $::MW::exchan $chan] < 0} {
set target [string map {{ } {_}} [lrange $text 1 end]]
putserv "PRIVMSG $chan :https://$project.$::MW::domain/wiki/Special:Block/$target"
} elseif {[lsearch -nocase $::MW::exchan $chan] < 0} {
set target [string map {{ } {_}} [lrange $text 0 end]]
putserv "PRIVMSG $chan :https://$::MW::def.$::MW::domain/wiki/Special:Block/$target"
}
}
proc ::MW::Log {nick host hand chan text} {
set text [split $text]
set project [lindex $text 0]
if {[lsearch -nocase $::MW::lang $project] >= 0 && [lsearch -nocase $::MW::exchan $chan] < 0} {
set target [string map {{ } {_}} [lrange $text 1 end]]
putserv "PRIVMSG $chan :User logs: https://$project.$::MW::domain/wiki/Special:Log/$target"
} elseif {[lsearch -nocase $::MW::exchan $chan] < 0} {
set target [string map {{ } {_}} [lrange $text 0 end]]
putserv "PRIVMSG $chan :User logs: https://$::MW::def.$::MW::domain/wiki/Special:Log/$target"
}
}
proc ::MW::ipintel {nick host hand chan text} {
set target [string map {{ } {_}} [lrange [split $text] 0 end]]
if {[lsearch -nocase $::MW::exchan $chan] < 0} {
putserv "PRIVMSG $chan :WHOIS Lookup https://tools.wmflabs.org/whois/gateway.py?lookup=true&ip=$target" }
}
proc ::MW::udc {nick host hand chan text} {
set target [string map {{ } {+}} [lrange [join [split $text]] 0 end]]
if {[lsearch -nocase $::MW::exchan $chan] < 0} {
putserv "PRIVMSG $chan :Urban Dictionary lookup: https://www.urbandictionary.com/define.php?term=$target"
}
}
proc ::MW::Google {nick host hand chan text} {
set search [string map {{ } {+}} [lrange [join [split $text]] 0 end]]
if {[lsearch -nocase $::MW::exchan $chan] < 0} {
putserv "PRIVMSG $chan :Google results: https://www.google.com/search?q=$search"
}
}
if {$::MW::domain == "example.com" || $::MW::lang == "subdomain1 subdomain2 subdomain3" || $::MW::def == "default"} {
die "You didn't configure MediaWiki Link Generator..."
}
putlog "Operator873's MediaWiki Link Generator loaded."