forked from tliff/schnapsdrossel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.rb
More file actions
118 lines (96 loc) · 2.66 KB
/
Copy pathmain.rb
File metadata and controls
118 lines (96 loc) · 2.66 KB
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
require 'cinch'
require 'open-uri'
require 'uri'
require 'pp'
require 'yaml'
require 'htmlentities'
require 'logger'
$:.unshift File.expand_path( '../lib', __FILE__ )
require 'twitter_plugin.rb'
require 'spotify_plugin.rb'
require 'youtube_plugin.rb'
require 'definitions_plugin.rb'
require 'valinfo_plugin.rb'
require './config.rb'
module Cinch
module Utilities
# @since 2.0.0
# @api private
module Encoding
def self.encode_incoming(string, encoding)
string = string.dup
if encoding == :irc
# If incoming text is valid UTF-8, it will be interpreted as
# such. If it fails validation, a CP1252 -> UTF-8 conversion
# is performed. This allows you to see non-ASCII from mIRC
# users (non-UTF-8) and other users sending you UTF-8.
#
# (from http://xchat.org/encoding/#hybrid)
string.force_encoding("UTF-8")
if !string.valid_encoding?
string.force_encoding("CP1252").encode!("UTF-8", {:invalid => :replace, :undef => :replace})
end
else
string.force_encoding(encoding).encode!({:invalid => :replace, :undef => :replace})
string = string.chars.select { |c| c.valid_encoding? }.join
end
return string
end
def self.encode_outgoing(string, encoding)
string = string.dup
if encoding == :irc
encoding = "UTF-8"
end
return string.encode!(encoding).force_encoding("ASCII-8BIT")
end
end
end
end
class CinchLogger
def method_missing(name, *arg)
pp arg
end
end
module Schnapsdrossel
ALLOWED_HOSTS = [
'tliff.users.quakenet.org',
'gix-.users.quakenet.org',
'Raim-I.users.quakenet.org'
].freeze
access_checker = -> (user) {
ALLOWED_HOSTS.include?(user.host)
}
bot = Cinch::Bot.new do |bot|
configure do |c|
YAML.load(File.read('config/bot.yml')).each do |k,v|
c.send("#{k}=".to_sym, v)
end
c.plugins.plugins = [
SpotifyPlugin,
DefinitionsPlugin,
TwitterPlugin,
YoutubePlugin,
ValinfoPlugin
]
c.plugins.options = {
DefinitionsPlugin => {
access_checker: access_checker
},
TwitterPlugin => {channel: c.channels.first},
}
end
bot.loggers = CinchLogger.new
on :channel, /^\.reload$/ do |m|
@bot.quit("brb") if access_checker.call(m.user)
end
on :channel, /^\.die$/ do |m|
exit 0 if access_checker.call(m.user)
end
on :channel, /^\.eval / do |m|
if access_checker.call(m.user)
m.channel.msg eval(m.message.gsub(/^\.eval /,''))
end
end
end
bot.start
end