mod_spox 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +2 -0
- data/INSTALL +9 -0
- data/README +33 -0
- data/bin/mod_spox +60 -0
- data/data/mod_spox/extras/Tester.rb +14 -0
- data/data/mod_spox/plugins/Authenticator.rb +245 -0
- data/data/mod_spox/plugins/BotNick.rb +18 -0
- data/data/mod_spox/plugins/Initializer.rb +41 -0
- data/data/mod_spox/plugins/Joiner.rb +13 -0
- data/data/mod_spox/plugins/Parter.rb +22 -0
- data/data/mod_spox/plugins/PluginLoader.rb +136 -0
- data/data/mod_spox/plugins/Ponger.rb +14 -0
- data/data/mod_spox/plugins/Quitter.rb +14 -0
- data/lib/mod_spox/Action.rb +73 -0
- data/lib/mod_spox/BaseConfig.rb +48 -0
- data/lib/mod_spox/Bot.rb +472 -0
- data/lib/mod_spox/BotConfig.rb +54 -0
- data/lib/mod_spox/ConfigurationWizard.rb +178 -0
- data/lib/mod_spox/Database.rb +25 -0
- data/lib/mod_spox/Exceptions.rb +35 -0
- data/lib/mod_spox/Helpers.rb +35 -0
- data/lib/mod_spox/Loader.rb +79 -0
- data/lib/mod_spox/Logger.rb +31 -0
- data/lib/mod_spox/MessageFactory.rb +73 -0
- data/lib/mod_spox/Monitors.rb +59 -0
- data/lib/mod_spox/Pipeline.rb +148 -0
- data/lib/mod_spox/Plugin.rb +18 -0
- data/lib/mod_spox/PluginManager.rb +105 -0
- data/lib/mod_spox/Pool.rb +50 -0
- data/lib/mod_spox/Socket.rb +171 -0
- data/lib/mod_spox/Timer.rb +138 -0
- data/lib/mod_spox/handlers/BadNick.rb +16 -0
- data/lib/mod_spox/handlers/Bounce.rb +15 -0
- data/lib/mod_spox/handlers/Created.rb +16 -0
- data/lib/mod_spox/handlers/Handler.rb +31 -0
- data/lib/mod_spox/handlers/Invite.rb +19 -0
- data/lib/mod_spox/handlers/Join.rb +30 -0
- data/lib/mod_spox/handlers/Kick.rb +24 -0
- data/lib/mod_spox/handlers/LuserChannels.rb +16 -0
- data/lib/mod_spox/handlers/LuserClient.rb +16 -0
- data/lib/mod_spox/handlers/LuserMe.rb +14 -0
- data/lib/mod_spox/handlers/LuserOp.rb +16 -0
- data/lib/mod_spox/handlers/LuserUnknown.rb +16 -0
- data/lib/mod_spox/handlers/Mode.rb +47 -0
- data/lib/mod_spox/handlers/Motd.rb +30 -0
- data/lib/mod_spox/handlers/MyInfo.rb +21 -0
- data/lib/mod_spox/handlers/Names.rb +54 -0
- data/lib/mod_spox/handlers/Nick.rb +24 -0
- data/lib/mod_spox/handlers/NickInUse.rb +16 -0
- data/lib/mod_spox/handlers/Notice.rb +32 -0
- data/lib/mod_spox/handlers/Part.rb +19 -0
- data/lib/mod_spox/handlers/Ping.rb +16 -0
- data/lib/mod_spox/handlers/Pong.rb +16 -0
- data/lib/mod_spox/handlers/Privmsg.rb +27 -0
- data/lib/mod_spox/handlers/Quit.rb +21 -0
- data/lib/mod_spox/handlers/Topic.rb +29 -0
- data/lib/mod_spox/handlers/Welcome.rb +34 -0
- data/lib/mod_spox/handlers/Who.rb +60 -0
- data/lib/mod_spox/handlers/Whois.rb +63 -0
- data/lib/mod_spox/handlers/YourHost.rb +17 -0
- data/lib/mod_spox/messages/incoming/BadNick.rb +15 -0
- data/lib/mod_spox/messages/incoming/Bounce.rb +17 -0
- data/lib/mod_spox/messages/incoming/Created.rb +14 -0
- data/lib/mod_spox/messages/incoming/Invite.rb +20 -0
- data/lib/mod_spox/messages/incoming/Join.rb +18 -0
- data/lib/mod_spox/messages/incoming/Kick.rb +25 -0
- data/lib/mod_spox/messages/incoming/LuserChannels.rb +14 -0
- data/lib/mod_spox/messages/incoming/LuserClient.rb +23 -0
- data/lib/mod_spox/messages/incoming/LuserMe.rb +17 -0
- data/lib/mod_spox/messages/incoming/LuserOp.rb +14 -0
- data/lib/mod_spox/messages/incoming/LuserUnknown.rb +14 -0
- data/lib/mod_spox/messages/incoming/Message.rb +22 -0
- data/lib/mod_spox/messages/incoming/Mode.rb +41 -0
- data/lib/mod_spox/messages/incoming/Motd.rb +17 -0
- data/lib/mod_spox/messages/incoming/MyInfo.rb +23 -0
- data/lib/mod_spox/messages/incoming/Names.rb +23 -0
- data/lib/mod_spox/messages/incoming/Nick.rb +25 -0
- data/lib/mod_spox/messages/incoming/NickInUse.rb +14 -0
- data/lib/mod_spox/messages/incoming/Notice.rb +8 -0
- data/lib/mod_spox/messages/incoming/Part.rb +20 -0
- data/lib/mod_spox/messages/incoming/Ping.rb +17 -0
- data/lib/mod_spox/messages/incoming/Pong.rb +8 -0
- data/lib/mod_spox/messages/incoming/Privmsg.rb +64 -0
- data/lib/mod_spox/messages/incoming/Quit.rb +17 -0
- data/lib/mod_spox/messages/incoming/Topic.rb +20 -0
- data/lib/mod_spox/messages/incoming/TopicInfo.rb +20 -0
- data/lib/mod_spox/messages/incoming/Welcome.rb +26 -0
- data/lib/mod_spox/messages/incoming/Who.rb +17 -0
- data/lib/mod_spox/messages/incoming/Whois.rb +47 -0
- data/lib/mod_spox/messages/incoming/YourHost.rb +17 -0
- data/lib/mod_spox/messages/internal/BotInitialized.rb +11 -0
- data/lib/mod_spox/messages/internal/ChangeNick.rb +15 -0
- data/lib/mod_spox/messages/internal/Connected.rb +20 -0
- data/lib/mod_spox/messages/internal/ConnectionFailed.rb +23 -0
- data/lib/mod_spox/messages/internal/Disconnected.rb +8 -0
- data/lib/mod_spox/messages/internal/Disconnecting.rb +8 -0
- data/lib/mod_spox/messages/internal/EstablishConnection.rb +22 -0
- data/lib/mod_spox/messages/internal/HaltBot.rb +8 -0
- data/lib/mod_spox/messages/internal/NickRequest.rb +8 -0
- data/lib/mod_spox/messages/internal/NickResponse.rb +14 -0
- data/lib/mod_spox/messages/internal/PluginLoadRequest.rb +20 -0
- data/lib/mod_spox/messages/internal/PluginLoadResponse.rb +16 -0
- data/lib/mod_spox/messages/internal/PluginModuleRequest.rb +13 -0
- data/lib/mod_spox/messages/internal/PluginModuleResponse.rb +17 -0
- data/lib/mod_spox/messages/internal/PluginReload.rb +8 -0
- data/lib/mod_spox/messages/internal/PluginRequest.rb +17 -0
- data/lib/mod_spox/messages/internal/PluginResponse.rb +20 -0
- data/lib/mod_spox/messages/internal/PluginUnloadRequest.rb +8 -0
- data/lib/mod_spox/messages/internal/PluginUnloadResponse.rb +8 -0
- data/lib/mod_spox/messages/internal/Request.rb +15 -0
- data/lib/mod_spox/messages/internal/Response.rb +15 -0
- data/lib/mod_spox/messages/internal/Shutdown.rb +8 -0
- data/lib/mod_spox/messages/internal/SignaturesUpdate.rb +8 -0
- data/lib/mod_spox/messages/internal/StatusRequest.rb +9 -0
- data/lib/mod_spox/messages/internal/StatusResponse.rb +17 -0
- data/lib/mod_spox/messages/internal/TimerAdd.rb +27 -0
- data/lib/mod_spox/messages/internal/TimerClear.rb +8 -0
- data/lib/mod_spox/messages/internal/TimerRemove.rb +15 -0
- data/lib/mod_spox/messages/internal/TimerResponse.rb +26 -0
- data/lib/mod_spox/messages/internal/TriggersUpdate.rb +8 -0
- data/lib/mod_spox/messages/outgoing/Admin.rb +15 -0
- data/lib/mod_spox/messages/outgoing/Away.rb +10 -0
- data/lib/mod_spox/messages/outgoing/ChannelMode.rb +25 -0
- data/lib/mod_spox/messages/outgoing/Connect.rb +24 -0
- data/lib/mod_spox/messages/outgoing/Die.rb +9 -0
- data/lib/mod_spox/messages/outgoing/Info.rb +15 -0
- data/lib/mod_spox/messages/outgoing/Invite.rb +19 -0
- data/lib/mod_spox/messages/outgoing/Ison.rb +15 -0
- data/lib/mod_spox/messages/outgoing/Join.rb +19 -0
- data/lib/mod_spox/messages/outgoing/Kick.rb +23 -0
- data/lib/mod_spox/messages/outgoing/Kill.rb +19 -0
- data/lib/mod_spox/messages/outgoing/Links.rb +19 -0
- data/lib/mod_spox/messages/outgoing/List.rb +19 -0
- data/lib/mod_spox/messages/outgoing/Lusers.rb +19 -0
- data/lib/mod_spox/messages/outgoing/Motd.rb +16 -0
- data/lib/mod_spox/messages/outgoing/Names.rb +20 -0
- data/lib/mod_spox/messages/outgoing/Nick.rb +16 -0
- data/lib/mod_spox/messages/outgoing/Notice.rb +11 -0
- data/lib/mod_spox/messages/outgoing/Oper.rb +19 -0
- data/lib/mod_spox/messages/outgoing/Part.rb +19 -0
- data/lib/mod_spox/messages/outgoing/Pass.rb +16 -0
- data/lib/mod_spox/messages/outgoing/Ping.rb +10 -0
- data/lib/mod_spox/messages/outgoing/Pong.rb +17 -0
- data/lib/mod_spox/messages/outgoing/Privmsg.rb +19 -0
- data/lib/mod_spox/messages/outgoing/Quit.rb +10 -0
- data/lib/mod_spox/messages/outgoing/Rehash.rb +9 -0
- data/lib/mod_spox/messages/outgoing/Restart.rb +9 -0
- data/lib/mod_spox/messages/outgoing/ServList.rb +19 -0
- data/lib/mod_spox/messages/outgoing/Simple.rb +12 -0
- data/lib/mod_spox/messages/outgoing/Squery.rb +19 -0
- data/lib/mod_spox/messages/outgoing/Squit.rb +19 -0
- data/lib/mod_spox/messages/outgoing/Stats.rb +18 -0
- data/lib/mod_spox/messages/outgoing/Summon.rb +23 -0
- data/lib/mod_spox/messages/outgoing/Time.rb +15 -0
- data/lib/mod_spox/messages/outgoing/Topic.rb +19 -0
- data/lib/mod_spox/messages/outgoing/Trace.rb +15 -0
- data/lib/mod_spox/messages/outgoing/Unaway.rb +9 -0
- data/lib/mod_spox/messages/outgoing/User.rb +23 -0
- data/lib/mod_spox/messages/outgoing/UserHost.rb +15 -0
- data/lib/mod_spox/messages/outgoing/UserMode.rb +19 -0
- data/lib/mod_spox/messages/outgoing/Users.rb +15 -0
- data/lib/mod_spox/messages/outgoing/Version.rb +16 -0
- data/lib/mod_spox/messages/outgoing/Who.rb +19 -0
- data/lib/mod_spox/messages/outgoing/WhoWas.rb +23 -0
- data/lib/mod_spox/messages/outgoing/Whois.rb +19 -0
- data/lib/mod_spox/migration/001_create_auths.rb +13 -0
- data/lib/mod_spox/migration/001_create_channel.rb +13 -0
- data/lib/mod_spox/migration/001_create_channel_modes.rb +13 -0
- data/lib/mod_spox/migration/001_create_config.rb +13 -0
- data/lib/mod_spox/migration/001_create_nick_channels.rb +13 -0
- data/lib/mod_spox/migration/001_create_nick_modes.rb +13 -0
- data/lib/mod_spox/migration/001_create_nicks.rb +13 -0
- data/lib/mod_spox/migration/001_create_servers.rb +13 -0
- data/lib/mod_spox/migration/001_create_settings.rb +13 -0
- data/lib/mod_spox/migration/001_create_signatures.rb +13 -0
- data/lib/mod_spox/migration/001_create_triggers.rb +13 -0
- data/lib/mod_spox/models/Auth.rb +79 -0
- data/lib/mod_spox/models/AuthGroup.rb +15 -0
- data/lib/mod_spox/models/Channel.rb +47 -0
- data/lib/mod_spox/models/ChannelMode.rb +14 -0
- data/lib/mod_spox/models/Config.rb +31 -0
- data/lib/mod_spox/models/Group.rb +13 -0
- data/lib/mod_spox/models/Nick.rb +110 -0
- data/lib/mod_spox/models/NickChannel.rb +43 -0
- data/lib/mod_spox/models/NickMode.rb +18 -0
- data/lib/mod_spox/models/Server.rb +12 -0
- data/lib/mod_spox/models/Setting.rb +40 -0
- data/lib/mod_spox/models/Signature.rb +30 -0
- data/lib/mod_spox/models/Trigger.rb +9 -0
- data/lib/mod_spox/rfc2812.rb +171 -0
- metadata +261 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module ModSpox
|
|
2
|
+
module Messages
|
|
3
|
+
module Outgoing
|
|
4
|
+
class WhoWas
|
|
5
|
+
# nick to whowas
|
|
6
|
+
attr_reader :nick
|
|
7
|
+
# number of entries to return
|
|
8
|
+
attr_reader :count
|
|
9
|
+
# target server
|
|
10
|
+
attr_reader :target
|
|
11
|
+
# nick:: nick to whowas
|
|
12
|
+
# count:: number of entries to return
|
|
13
|
+
# target:: target server
|
|
14
|
+
# Information about a nick that no longer exists
|
|
15
|
+
def initialize(nick, count='', target='')
|
|
16
|
+
@nick = nick
|
|
17
|
+
@count = count
|
|
18
|
+
@target = target
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module ModSpox
|
|
2
|
+
module Messages
|
|
3
|
+
module Outgoing
|
|
4
|
+
class Whois
|
|
5
|
+
# nick to whois
|
|
6
|
+
attr_reader :nick
|
|
7
|
+
# server to query
|
|
8
|
+
attr_reader :target_server
|
|
9
|
+
# nick:: nick to whois
|
|
10
|
+
# target_server:: server to query
|
|
11
|
+
# Query information about a user
|
|
12
|
+
def initialize(nick, target_server='')
|
|
13
|
+
@nick = nick
|
|
14
|
+
@target_server = target_server
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
require 'digest/sha1'
|
|
2
|
+
module ModSpox
|
|
3
|
+
module Models
|
|
4
|
+
|
|
5
|
+
# Attributes provided by model:
|
|
6
|
+
# password:: Password to autenticate against
|
|
7
|
+
# services:: Authentication by nickserv
|
|
8
|
+
# mask:: Mask to authenticate source against
|
|
9
|
+
# authed:: Nick has authenticated
|
|
10
|
+
class Auth < Sequel::Model(:auths)
|
|
11
|
+
|
|
12
|
+
# Nick associated with this Auth
|
|
13
|
+
def nick
|
|
14
|
+
Nick[nick_id]
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def services
|
|
18
|
+
s = values[:services]
|
|
19
|
+
if(s == 0 || s == '0' || !s)
|
|
20
|
+
return false
|
|
21
|
+
else
|
|
22
|
+
return true
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Groups this auth is a member of
|
|
27
|
+
def groups
|
|
28
|
+
# we grab IDs, then the object. Otherwise we get sync problems
|
|
29
|
+
group_id = []
|
|
30
|
+
AuthGroup.filter(:auth_id => pk).each do |ag|
|
|
31
|
+
group_id << ag.group_id
|
|
32
|
+
end
|
|
33
|
+
group = []
|
|
34
|
+
group_id.each{|id| group << Group[id]}
|
|
35
|
+
return group
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Add group to this auth's list
|
|
39
|
+
def group=(group)
|
|
40
|
+
AuthGroup.find_or_create(:auth_id => pk, :group_id => group.pk)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Remove given group from auth
|
|
44
|
+
def remove_group(group)
|
|
45
|
+
AuthGroup.filter(:auth_id => pk, :group_id => group.pk).each{|g|g.destroy}
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Set services (nickserv) identification
|
|
49
|
+
def services_identified=(val)
|
|
50
|
+
set :authed => true if val && services
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# pass:: password to compare
|
|
54
|
+
# Check and authenticate against password
|
|
55
|
+
def check_password(pass)
|
|
56
|
+
if(Digest::SHA1.hexdigest(pass) == password)
|
|
57
|
+
set :authed => true
|
|
58
|
+
return true
|
|
59
|
+
else
|
|
60
|
+
return false
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def password=(pass)
|
|
65
|
+
set :password => Digest::SHA1.hexdigest(pass)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# source:: source to apply mask to
|
|
69
|
+
# Check and authenticate by mask against source
|
|
70
|
+
def check_mask(source)
|
|
71
|
+
if(source =~ /^#{mask}$/)
|
|
72
|
+
set :authed => true
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
module ModSpox
|
|
2
|
+
module Models
|
|
3
|
+
|
|
4
|
+
# Attributes provided by model:
|
|
5
|
+
# name:: Channel name
|
|
6
|
+
# password:: Channel password
|
|
7
|
+
# autojoin:: Set bot to autojoin this channel
|
|
8
|
+
# topic:: Channel topic
|
|
9
|
+
# quiet:: Silence the bot in this channel
|
|
10
|
+
# parked:: Bot is currently in this channel
|
|
11
|
+
class Channel < Sequel::Model(:channels)
|
|
12
|
+
|
|
13
|
+
# Modes for this channel
|
|
14
|
+
def channel_modes
|
|
15
|
+
ChannelMode.filter(:channel_id => pk)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Nicks residing within this channel
|
|
19
|
+
def nicks
|
|
20
|
+
NickChannel.filter(:channel_id => pk)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Adds a nick to this channel
|
|
24
|
+
def nick_add(nick)
|
|
25
|
+
NickChannel.find_or_create(:channel_id => pk, :nick_id => nick.pk)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Removes a nick from this channel
|
|
29
|
+
def nick_remove(nick)
|
|
30
|
+
NickChannel.filter(:channel_id => pk, :nick_id => nick.pk).first.destroy
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Removes all nicks from this channel
|
|
34
|
+
def clear_nicks
|
|
35
|
+
NickChannel.filter(:channel_id => pk, :nick_id => nick.pk).each{|o| o.destroy}
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Purges all channel information
|
|
39
|
+
def self.clean
|
|
40
|
+
Channel.set(:topic => nil, :parked => false)
|
|
41
|
+
ChannelMode.destroy_all
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module ModSpox
|
|
2
|
+
module Models
|
|
3
|
+
# Attributes provided by model:
|
|
4
|
+
# name:: name of the config item
|
|
5
|
+
# value:: value of the config item
|
|
6
|
+
#
|
|
7
|
+
# It is important to note this model is for storing configuration
|
|
8
|
+
# values only. It will only store strings, not complex objects. If
|
|
9
|
+
# you need to store an object, use the Setting model.
|
|
10
|
+
class Config < Sequel::Model(:configs)
|
|
11
|
+
|
|
12
|
+
# key:: name of the config item
|
|
13
|
+
# Returns the value of config item named the given key
|
|
14
|
+
def self.[](key)
|
|
15
|
+
key = key.to_s if key.is_a?(Symbol)
|
|
16
|
+
match = Config.filter(:name => key).first
|
|
17
|
+
return match ? match.value : nil
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# key:: name of the config item
|
|
21
|
+
# val:: value of the config item
|
|
22
|
+
# Modifies or creates config item and stores the value
|
|
23
|
+
def self.[]=(key, val)
|
|
24
|
+
key = key.to_s if key.is_a?(Symbol)
|
|
25
|
+
model = Config.find_or_create(:name => key)
|
|
26
|
+
model.value = val
|
|
27
|
+
model.save
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
module ModSpox
|
|
2
|
+
module Models
|
|
3
|
+
# Attributes provided by model:
|
|
4
|
+
# nick:: nick string
|
|
5
|
+
# username:: username of the user
|
|
6
|
+
# real_name:: real name of the user
|
|
7
|
+
# address:: hostname/ip of the user
|
|
8
|
+
# source:: full source string of the user
|
|
9
|
+
# connected_at:: time user connected
|
|
10
|
+
# connected_to:: server user connected to
|
|
11
|
+
# seconds_idle:: seconds user has been idle
|
|
12
|
+
# visible:: can the bot see the user (is in a channel the bot is parked)
|
|
13
|
+
# away:: is nick away
|
|
14
|
+
# botnick:: is the nick of the bot
|
|
15
|
+
|
|
16
|
+
# TODO: for nick field -> "tack a COLLATE NOCASE onto the columns"
|
|
17
|
+
class Nick < Sequel::Model(:nicks)
|
|
18
|
+
|
|
19
|
+
def visible=(val)
|
|
20
|
+
unless(val)
|
|
21
|
+
set :username => nil
|
|
22
|
+
set :real_name => nil
|
|
23
|
+
set :address => nil
|
|
24
|
+
set :source => nil
|
|
25
|
+
set :connected_at => nil
|
|
26
|
+
set :connected_to => nil
|
|
27
|
+
set :seconds_idle => nil
|
|
28
|
+
set :away => false
|
|
29
|
+
end
|
|
30
|
+
set :visible => val
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def source=(mask)
|
|
34
|
+
set :source => mask
|
|
35
|
+
auth.check_mask(mask)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Auth model associated with nick
|
|
39
|
+
def auth
|
|
40
|
+
Auth.find_or_create(:nick_id => pk)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# AuthGroups nick is authed to
|
|
44
|
+
def auth_groups
|
|
45
|
+
groups = []
|
|
46
|
+
auth_ids = []
|
|
47
|
+
group_ids = []
|
|
48
|
+
auth = Auth.filter(:nick_id => pk, :authed => true).first
|
|
49
|
+
if(auth)
|
|
50
|
+
groups = auth.groups
|
|
51
|
+
end
|
|
52
|
+
Auth.where('mask is not null').each do |a|
|
|
53
|
+
Logger.log("Matching AUTH against #{a.mask}", 30)
|
|
54
|
+
if(source =~ /#{a.mask}/)
|
|
55
|
+
auth_ids << a.pk
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
auth_ids.each{|id| AuthGroup.filter(:auth_id => id).each{|ag| group_ids << ag.group_id}}
|
|
59
|
+
group_ids.each{|id| groups << Group[id]}
|
|
60
|
+
groups.uniq!
|
|
61
|
+
return groups
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Set nick as member of given group
|
|
65
|
+
def group=(group)
|
|
66
|
+
auth.group = group
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Remove nick from given group
|
|
70
|
+
def remove_group(group)
|
|
71
|
+
auth.remove_group(group)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# Modes associated with this nick
|
|
75
|
+
def nick_modes
|
|
76
|
+
NickMode.filter(:nick_id => pk)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Add channel nick is found in
|
|
80
|
+
def channel_add(channel)
|
|
81
|
+
NickChannel.find_or_create(:nick_id => pk, :channel_id => channel.pk)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Remove channel nick is no longer found in
|
|
85
|
+
def channel_remove(channel)
|
|
86
|
+
NickChannel.filter(:nick_id => pk, :channel_id => channel.pk).first.destroy
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# Remove all channels
|
|
90
|
+
def clear_channels
|
|
91
|
+
NickChannel.filter(:nick_id => pk).each{|o|o.destroy}
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Channels nick is currently in
|
|
95
|
+
def channels
|
|
96
|
+
NickChannel.filter(:nick_id => pk)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# Purge all nick information
|
|
100
|
+
def self.clean
|
|
101
|
+
Nick.set(:username => nil, :real_name => nil, :address => nil,
|
|
102
|
+
:source => nil, :connected_at => nil, :connected_to => nil,
|
|
103
|
+
:seconds_idle => nil, :away => false, :visible => false, :botnick => false)
|
|
104
|
+
NickMode.destroy_all
|
|
105
|
+
Auth.set(:authed => false)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
module ModSpox
|
|
2
|
+
module Models
|
|
3
|
+
# This model is for internal use only to provide a
|
|
4
|
+
# proper relation between Nick and Channel
|
|
5
|
+
class NickChannel < Sequel::Model(:nick_channels)
|
|
6
|
+
|
|
7
|
+
set_primary_key [:nick_id, :channel_id]
|
|
8
|
+
|
|
9
|
+
after_save do
|
|
10
|
+
c = Channel[channel_id]
|
|
11
|
+
n = Nick[nick_id]
|
|
12
|
+
n.visible = true
|
|
13
|
+
n.save
|
|
14
|
+
c.parked = true
|
|
15
|
+
c.save
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
after_destroy do
|
|
19
|
+
c = Channel[channel_id]
|
|
20
|
+
n = Nick[nick_id]
|
|
21
|
+
if(n.channels.size < 1)
|
|
22
|
+
n.visible = false
|
|
23
|
+
n.save
|
|
24
|
+
NickMode.filter(:nick_id => nick_id).each{|n|n.destroy}
|
|
25
|
+
end
|
|
26
|
+
if(c.nicks.size < 1)
|
|
27
|
+
c.parked = false
|
|
28
|
+
c.save
|
|
29
|
+
NickMode.filter(:channel_id => channel_id).each{|n|n.destroy}
|
|
30
|
+
ChannelMode.filter(:channel_id => channel_id).each{|n|n.destroy}
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def nick
|
|
35
|
+
Nick[nick_id]
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def channel
|
|
39
|
+
Channel[channel_id]
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module ModSpox
|
|
2
|
+
module Models
|
|
3
|
+
# Attributes provided by model:
|
|
4
|
+
# mode:: Mode that is set
|
|
5
|
+
class NickMode < Sequel::Model(:nick_modes)
|
|
6
|
+
|
|
7
|
+
# Nick mode is associated with
|
|
8
|
+
def nick
|
|
9
|
+
return Nick[nick_id]
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# Channel mode is associated with
|
|
13
|
+
def channel
|
|
14
|
+
return Channel[channel_id]
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module ModSpox
|
|
2
|
+
module Models
|
|
3
|
+
# Attributes provided by model:
|
|
4
|
+
# host:: hostname of server
|
|
5
|
+
# port:: port to connect to
|
|
6
|
+
# priority:: priority of this entry (higher number == greater priority)
|
|
7
|
+
# connected:: bot is connected to this server
|
|
8
|
+
class Server < Sequel::Model(:servers)
|
|
9
|
+
set_primary_key [:host, :port]
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
require 'base64'
|
|
2
|
+
|
|
3
|
+
module ModSpox
|
|
4
|
+
module Models
|
|
5
|
+
# Attributes provided by model:
|
|
6
|
+
# name:: name of the setting
|
|
7
|
+
# value:: value of the setting
|
|
8
|
+
#
|
|
9
|
+
# This model can be used to store complex objects. These objects are dumped
|
|
10
|
+
# and stored for later retrieval
|
|
11
|
+
class Setting < Sequel::Model(:settings)
|
|
12
|
+
|
|
13
|
+
def value=(val)
|
|
14
|
+
set(:value => Base64.encode64(Marshal.dump(val)))
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def value
|
|
18
|
+
return values[:value] ? Marshal.load(Base64.decode64(values[:value])) : nil
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# key:: name of the setting
|
|
22
|
+
# Returns the setting with the given name
|
|
23
|
+
def self.[](key)
|
|
24
|
+
key = key.to_s if key.is_a?(Symbol)
|
|
25
|
+
setting = Setting.filter(:name => key).first
|
|
26
|
+
return setting ? setting.value : nil
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# key:: name of the setting
|
|
30
|
+
# val:: value of the setting
|
|
31
|
+
# Stores the val in setting named by the given key
|
|
32
|
+
def self.[]=(key, val)
|
|
33
|
+
key = key.to_s if key.is_a?(Symbol)
|
|
34
|
+
model = Setting.find_or_create(:name => key)
|
|
35
|
+
model.value = val
|
|
36
|
+
model.save
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module ModSpox
|
|
2
|
+
module Models
|
|
3
|
+
# Attributes provided by model:
|
|
4
|
+
# signature:: regex signature
|
|
5
|
+
# params:: Array of parameters to match in signature
|
|
6
|
+
# method:: method to call when matched
|
|
7
|
+
# plugin:: plugin to call when matched
|
|
8
|
+
# description:: description of trigger
|
|
9
|
+
class Signature < Sequel::Model(:signatures)
|
|
10
|
+
|
|
11
|
+
def params=(prms)
|
|
12
|
+
raise InvalidType.new('Parameter names must be provided in an array') unless prms.kind_of?(Array)
|
|
13
|
+
set(:params => prms.reverse.join('|'))
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def params
|
|
17
|
+
return values[:params].nil? ? [] : values[:params].split('|')
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def group
|
|
21
|
+
Group[group_id]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def group=(group)
|
|
25
|
+
set :group_id => group.pk
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|