-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtestbot.rb
115 lines (93 loc) · 3.36 KB
/
testbot.rb
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
# -*- coding: utf-8 -*-
#
# This is a sample robot using some of the plugins in this
# repository, mainly intended for testing purposes. You may
# find it useful as a working usage example of some of the
# plugins.
# Require Cinch
require "cinch"
require "fileutils"
# Require our plugins
require_relative "plugins/echo"
require_relative "plugins/logplus"
require_relative "plugins/link_info"
require_relative "plugins/tickets"
require_relative "plugins/vote"
require_relative "plugins/seen"
require_relative "plugins/quit"
require_relative "plugins/channel_record"
FileUtils.mkdir_p("/tmp/logs/plainlogs")
FileUtils.mkdir_p("/tmp/logs/htmllogs")
# Define the robot
cinch = Cinch::Bot.new do
configure do |config|
########################################
# Cinch options
# Server stuff
config.server = "localhost"
config.port = 6667
config.ssl.use = false
config.ssl.verify = false
# User stuff
config.channels = ["#test"]
config.nick = "mega-cinch"
config.user = "cinch"
########################################
# Plugin options
# Default prefix is the bot’s name
config.plugins.prefix = lambda{|msg| Regexp.compile("^#{Regexp.escape(msg.bot.nick)}:?\s*")}
config.plugins.options[Cinch::LogPlus] = {
:plainlogdir => "/tmp/logs/plainlogs",
:htmllogdir => "/tmp/logs/htmllogs"
}
config.plugins.options[Cinch::Tickets] = {
:url => "http://example.org/tickets/%d"
}
config.plugins.options[Cinch::Seen] = {
:file => "/tmp/seenlog.dat"
}
config.plugins.options[Cinch::Vote] = {
:auth_required => false,
:voters => %w[Quintus]
}
config.plugins.options[Cinch::ChannelRecord] = {
:file => "/tmp/record.dat"
}
#
## List of plugins to load
config.plugins.plugins = [Cinch::Echo, Cinch::Quit, Cinch::ChannelRecord]
end
trap "SIGINT" do
bot.log("Cought SIGINT, quitting...", :info)
bot.quit
end
trap "SIGTERM" do
bot.log("Cought SIGTERM, quitting...", :info)
bot.quit
end
on :message, /foo/ do |msg|
str = "Testing colors:"
Cinch::Formatting::Colors.each_key do |color|
str << " " << Cinch::Formatting.format(color, color.to_s)
end
str << " " << Cinch::Formatting.format(:bold, "bold text")
str << " " << Cinch::Formatting.format(:yellow, Cinch::Formatting.format(:bold, "yellow bold text"))
str << " " << Cinch::Formatting.format(:underline, "underlined text")
str << " " << Cinch::Formatting.format(:red, Cinch::Formatting.format(:underline, "red underlined text"))
str << " " << Cinch::Formatting.format(:green, Cinch::Formatting.format(:bold, Cinch::Formatting.format(:underline, "green bold underlined text")))
str << " Normal again."
str << " " << Cinch::Formatting.format(:green, :yellow, "Green on yellow background.")
str << " " << Cinch::Formatting.format(:green, :yellow, Cinch::Formatting.format(:italic, "Italic green on yellow background."))
p(str)
msg.reply(str)
end
# Set up a logger so we have something more persistant
# than $stderr. Note this sadly cannot be done in a
# plugin, because plugins are loaded after a good number
# of log messages have already been created.
file = open("/tmp/cinch.log", "a")
file.sync = true
loggers.push(Cinch::Logger::FormattedLogger.new(file))
loggers.first.level = :debug
end
cinch.start