Compare commits

...

40 Commits

Author SHA1 Message Date
Arthur Poulet 3a3fd6f190
Merge branch 'Lucie-Dispot-master' 2016-05-15 00:04:17 +02:00
Lucie bec6b9436b Added kick and ops plugins 2016-05-14 23:32:54 +02:00
Arthur Poulet 7946dcc9cf strip sent messages 2016-03-26 19:38:33 +01:00
Arthur Poulet 9826602375 add diceroller 2016-03-21 16:30:10 +01:00
Arthur Poulet 4480cabf5a add eip, fix user 2016-03-21 16:19:46 +01:00
Arthur Poulet c588216486 add dep 'i18n' 2015-12-30 22:08:08 +01:00
Arthur Poulet de6f2d82a1 Remove useless assignemnt
close #22
2015-11-28 14:28:32 +01:00
Arthur Poulet 375118ed09 Large improvment for cequetudisnaaucunsens plugin 2015-11-28 14:21:18 +01:00
Arthur Poulet e07d60d03d fix primary email and email from system 2015-11-22 01:42:58 +01:00
Arthur Poulet 36f38abcf0 Improve puppet plugin
- add email system
- improve mail display
- improve privacy
2015-11-21 22:28:37 +01:00
Arthur Poulet b4c3f0d398 fix anecdote 2015-11-21 22:12:41 +01:00
Arthur Poulet 180ea02a76 remove bad joke 2015-11-21 00:33:35 +01:00
Arthur Poulet 9b0a7fe99f Fix readme 2015-11-20 12:51:22 +01:00
Arthur Poulet 44750ae719 add plugin Anecdote to readme 2015-11-20 12:03:26 +01:00
Arthur Poulet 8419a2d383 fix iaa and improve anecdote 2015-11-18 11:37:22 +01:00
Arthur Poulet 415b3c2eb7 fix anecdote 2015-11-18 00:50:55 +01:00
Arthur Poulet 5f6fa860a5 improve anecdote 2015-11-18 00:47:43 +01:00
Arthur Poulet a07a30c858 add anecdote 2015-11-18 00:22:29 +01:00
Arthur Poulet 45fe7b5a07 fix security on iaa 2015-11-18 00:21:56 +01:00
Arthur Poulet 4f49c528af add messaging system 2015-11-13 20:53:54 +01:00
Arthur Poulet efa044b10d fix plugin points (created_at) 2015-11-11 21:54:19 +01:00
Arthur Poulet ea9dc759e9 Improve help plugin (avoid flood)
close #23
2015-11-11 12:17:18 +01:00
Arthur Poulet 6466b590ab update github 2015-10-29 14:46:02 +01:00
Arthur Poulet 5a8e5f8594 improve iaa plugin: prepare data prospection :D 2015-10-23 19:25:16 +02:00
Arthur Poulet 3cca4168a1 Add encryption module 2015-10-22 11:49:17 +02:00
Arthur Poulet 479f24af6a add ep2 to root_me plugin 2015-10-18 18:00:01 +02:00
Arthur Poulet ff1b1a94b1 add root_me 2015-10-18 10:14:24 +02:00
Arthur Poulet 3299e661b2 fix plugin points 2015-10-18 10:12:43 +02:00
Arthur Poulet 37624c27c0 remove homophobic example :') 2015-10-12 23:51:18 +02:00
Arthur Poulet 59e5b813b9 add points nazi 2015-10-12 23:44:45 +02:00
Arthur Poulet 44e98fb7e9 improve plugin points with 2 commands 2015-10-12 01:04:11 +02:00
Arthur Poulet 567458a86e improve points statistics 2015-10-12 00:45:04 +02:00
Arthur Poulet 744714dc14 fix plugin points 2015-10-10 16:29:27 +02:00
Arthur Poulet 544a936457 IAA plugin compare with insensitive case 2015-10-06 21:28:37 +02:00
Arthur Poulet e16c9b9c65 improve points with stats 2015-10-02 17:46:01 +02:00
Arthur Poulet 2167740ad7 fix db points 2015-09-28 18:02:58 +02:00
Arthur Poulet d3a4885f6d fix points 2015-09-27 04:40:21 +02:00
Arthur Poulet 85993f6ac3 fix deps and points 2015-09-27 04:39:31 +02:00
Arthur Poulet cd52ea7077 fix points 2015-09-26 23:49:04 +02:00
Arthur Poulet bc2a7e9aeb improve points 2015-09-26 22:02:42 +02:00
28 changed files with 796 additions and 83 deletions

View File

@ -3,6 +3,9 @@ source 'https://rubygems.org'
#irc
gem 'cinch'
# scrap yt
gem 'mechanize'
# debug
gem 'pry'
gem 'colorize'
@ -18,5 +21,9 @@ gem 'sequel'
# gem 'sqlite3'
gem 'pg'
#encrypt
gem 'tor257'
#other
gem 'nomorebeer'
gem 'i18n'

View File

@ -1,22 +1,47 @@
GEM
remote: https://rubygems.org/
specs:
cinch (2.2.6)
cinch (2.2.7)
coderay (1.1.0)
colorize (0.7.7)
highline (1.7.3)
htauth (1.2.0)
highline (~> 1.6)
domain_name (0.5.25)
unf (>= 0.0.5, < 1.0.0)
htauth (2.0.0)
http-cookie (1.0.2)
domain_name (~> 0.5)
i18n (0.7.0)
mechanize (2.7.3)
domain_name (~> 0.5, >= 0.5.1)
http-cookie (~> 1.0)
mime-types (~> 2.0)
net-http-digest_auth (~> 1.1, >= 1.1.1)
net-http-persistent (~> 2.5, >= 2.5.2)
nokogiri (~> 1.4)
ntlm-http (~> 0.1, >= 0.1.1)
webrobots (>= 0.0.9, < 0.2)
method_source (0.8.2)
net-ping (1.7.7)
nomorebeer (1.0)
pg (0.18.2)
pry (0.10.1)
mime-types (2.6.2)
mini_portile (0.6.2)
net-http-digest_auth (1.4)
net-http-persistent (2.9.4)
net-ping (1.7.8)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
nomorebeer (1.1)
ntlm-http (0.1.1)
pg (0.18.3)
pry (0.10.3)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
sequel (4.25.0)
sequel (4.27.0)
slop (3.6.0)
tor257 (0.2)
nomorebeer (~> 1.1)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.1)
webrobots (0.1.1)
PLATFORMS
ruby
@ -25,11 +50,14 @@ DEPENDENCIES
cinch
colorize
htauth
i18n
mechanize
net-ping
nomorebeer
pg
pry
sequel
tor257
BUNDLED WITH
1.10.5
1.11.2

View File

@ -1,6 +1,6 @@
# botpop
[![Code Climate](https://codeclimate.com/github/pouleta/botpop/badges/gpa.svg)](https://codeclimate.com/github/pouleta/botpop)
[![GitHub version](https://badge.fury.io/gh/pouleta%2Fbotpop.svg)](http://badge.fury.io/gh/pouleta%2Fbotpop)
[![Code Climate](https://codeclimate.com/github/Nephos/botpop/badges/gpa.svg)](https://codeclimate.com/github/Nephos/botpop)
[![GitHub version](https://badge.fury.io/gh/Nephos%2Fbotpop.svg)](http://badge.fury.io/gh/Nephos%2Fbotpop)
## Requirements
@ -60,18 +60,19 @@ end
Some official plugins are developped. You can propose your own creation by pull request, or add snippets link to the wiki.
## List
- [Base](https://github.com/pouleta/botpop/blob/master/plugins/base.rb) : this is a basic plugin, providing __version, code, help, and troll__. It also provide a full groups's system.
- [Network](https://github.com/pouleta/botpop/blob/master/plugins/network.rb) : an usefull plugin with commands __ping, ping ip, ping http, traceroute, dos attack and poke__
- [Searchable](https://github.com/pouleta/botpop/blob/master/plugins/searchable.rb) : a little plugin providing irc research with engines like __google, wikipedia, ruby-doc, etc...__
- [Proxy](https://github.com/pouleta/botpop/blob/master/plugins/proxy.rb) : an audacious plugin to create user access to a local proxy
- [Log](https://github.com/pouleta/botpop/blob/master/plugins/log.rb) : simple logger
- [IAmAlive](https://github.com/pouleta/botpop/tree/master/plugins/iamalive) : a plugin to learn how to respond to the users. Fucking machine learning, oh yearh.
- [CeQueTuDisNaAucunSens](https://github.com/pouleta/botpop/tree/master/plugins/cequetudisnaaucunsens.rb) : a funny plugin to say "ce que tu dis n'a aucun sens" without any meaning.
- [Points](https://github.com/pouleta/botpop/tree/master/plugins/points.rb) : a gem to add points to an user. ``!p gay for_you``
- [Base](https://github.com/Nephos/botpop/blob/master/plugins/base.rb) : this is a basic plugin, providing __version, code, help, and troll__. It also provide a full groups's system.
- [Network](https://github.com/Nephos/botpop/blob/master/plugins/network.rb) : an usefull plugin with commands __ping, ping ip, ping http, traceroute, dos attack and poke__
- [Searchable](https://github.com/Nephos/botpop/blob/master/plugins/searchable.rb) : a little plugin providing irc research with engines like __google, wikipedia, ruby-doc, etc...__
- [Proxy](https://github.com/Nephos/botpop/blob/master/plugins/proxy.rb) : an audacious plugin to create user access to a local proxy
- [Log](https://github.com/Nephos/botpop/blob/master/plugins/log.rb) : simple logger
- [IAmAlive](https://github.com/Nephos/botpop/tree/master/plugins/iamalive) : a plugin to learn how to respond to the users. Fucking machine learning, oh yearh.
- [CeQueTuDisNaAucunSens](https://github.com/Nephos/botpop/tree/master/plugins/cequetudisnaaucunsens.rb) : a funny plugin to say "ce que tu dis n'a aucun sens" without any meaning.
- [Points](https://github.com/Nephos/botpop/tree/master/plugins/points.rb) : a gem to add points to an user. ``!p noob for_you``
- [Anecdote](https://github.com/Nephos/botpop/blob/master/plugins/anecdote.rb) : a cool meme generator plugin with nazi and youtuber. French meme.
### In version 0.X, not upgraded to v1
- [Coupon](https://github.com/pouleta/botpop/blob/master/plugins/coupons.rb) : the original aim of the bot. It get coupons for the challenge __pathwar__
- [Intranet](https://github.com/pouleta/botpop/blob/master/plugins/intranet.rb) : an useless plugin to check the intranet of epitech
- [Coupon](https://github.com/Nephos/botpop/blob/master/plugins/coupons.rb) : the original aim of the bot. It get coupons for the challenge __pathwar__
- [Intranet](https://github.com/Nephos/botpop/blob/master/plugins/intranet.rb) : an useless plugin to check the intranet of epitech
## Create your own
@ -82,7 +83,7 @@ You should take the time to read the documentation before developping anything.
### Example of new plugin
A full example of plugin code is provided in the commented file : [Example of Fury Plugin](https://github.com/pouleta/botpop/blob/master/plugins/example.rb)
A full example of plugin code is provided in the commented file : [Example of Fury Plugin](https://github.com/Nephos/botpop/blob/master/plugins/example.rb)
First, put your ruby code file in ``plugins/``, and put your code in the scope :
```ruby
@ -109,7 +110,7 @@ end
### Add entry to the !help command
The __official plugin__ [Base](https://github.com/pouleta/botpop/blob/master/plugins/base.rb) provides the command __!help__ and __!help plugin__.
The __official plugin__ [Base](https://github.com/Nephos/botpop/blob/master/plugins/base.rb) provides the command __!help__ and __!help plugin__.
It list the avaliable commands of the plugins. You can add your help to your plugin by providing a __HELP__ constant.
__The strings should be as short as possible.__

View File

@ -9,13 +9,28 @@ base:
password: toor
database: botpop_base
dice:
enable: true
eip:
enable: true
rootme:
enable: false
points:
enable: true
anecdote:
enable: true
log:
enable: true
default_started: false
encrypt:
enable: true
puppet:
enable: true
@ -115,11 +130,6 @@ iamalive:
cequetudisnaaucunsens:
enabled: true
apoil:
enable: true
words:
- fille
saygoodbye:
chapui_s:
- "@chapui_s t'es là ?"

46
plugins/anecdote.rb Normal file
View File

@ -0,0 +1,46 @@
require 'nokogiri'
require 'net/http'
class Anecdote < Botpop::Plugin
include Cinch::Plugin
match(/!a(necdote)? (.+)/, use_prefix: false, method: :exec_new)
HELP = ["!anecdote <...>"]
ENABLED = config['enable'].nil? ? false : config['enable']
CONFIG = config
def exec_new m, _, s
s.downcase!
f = I18n.transliterate(s)[0]
x = "Après je vous propose "
x += (%w(a e i o u y).include?(f) ? "d'" : "de ") if not s.match(/^(d'|de ).+/)
s = x + s
url = URI.parse 'http://memegenerator.net/create/instance'
post_data = {
'imageID' => 14185932,
'generatorID' => 5374051,
'watermark1' => 1,
'uploadtoImgur' => 'true',
'text0' => s,
'text1' => "Ca fera une petite anecdote !!",
}
meme = nil
begin
Net::HTTP.start url.host do |http|
post = Net::HTTP::Post.new url.path
post.set_form_data post_data
res = http.request post
location = res['Location']
redirect = url + location
get = Net::HTTP::Get.new redirect.request_uri
res = http.request get
doc = Nokogiri.HTML res.body
meme = doc.css("meta")[7]['content']
end
rescue => _err
end
m.reply meme ? meme : "Achtung ! ACHTUUUUNG !!!"
end
end

View File

@ -1,15 +0,0 @@
class APoil < Botpop::Plugin
include Cinch::Plugin
match(/.*/, use_prefix: false, method: :apoil)
ENABLED = config['enable'].nil? ? false : config['enable']
CONFIG = config
def apoil m
if not (CONFIG["words"] & m.message.split).empty?
m.reply "apoil"
end
end
end

View File

@ -1,5 +1,8 @@
#encoding: utf-8
require "i18n"
I18n.config.available_locales = [:en, :fr]
class Base < Botpop::Plugin
include Cinch::Plugin
include Botpop::Plugin::Database
@ -17,7 +20,8 @@ class Base < Botpop::Plugin
match(/^!user (\w+) group add (\w+)/, use_prefix: false, method: :user_group_add)
match(/^!user (\w+) group rm (\w+)/, use_prefix: false, method: :user_group_rm)
HELP = ["!troll [msg]", "!version", "!code", "!help [plugin]", "!cmds"]
HELP = ["!troll [msg]", "!version", "!code", "!help [plugin]", "!cmds",
"!user ls", "!user <name> group <ls|add|rm> [group]"]
ENABLED = config['enable'].nil? ? true : config['enable']
CONFIG = config
@ -39,21 +43,13 @@ class Base < Botpop::Plugin
def help_get_plugins_str
["Plugins found : " + Botpop::PLUGINS.size.to_s] +
Botpop::PLUGINS.map do |plugin|
plugin.to_s.split(':').last + ': ' + plugin::HELP.join(', ') rescue nil
plugin.to_s.split(':').last
end.compact
end
HELP_WAIT_DURATION = config['help_wait_duration'] || 120
def help m
@@help_lock ||= Mutex.new
if @@help_lock.try_lock
@@help_time = 0
help_get_plugins_str().each{|str| m.reply str} # display
help_wait_before_quit rescue nil
@@help_lock.unlock
else
m.reply "Help already sent #{@@help_time} seconds ago. Wait #{HELP_WAIT_DURATION - @@help_time} seconds more."
end
m.reply help_get_plugins_str.join(', ')
end
def exec_version m
@ -61,7 +57,7 @@ class Base < Botpop::Plugin
end
def exec_code m
m.reply "https://github.com/pouleta/botpop"
m.reply "https://github.com/Nephos/botpop"
end
def exec_help m

View File

@ -0,0 +1,12 @@
Sequel.migration do
change do
create_table(:messages) do
primary_key :id
String :author
String :dest
String :content
DateTime :created_at
DateTime :read_at
end
end
end

View File

@ -0,0 +1,14 @@
Sequel.migration do
change do
create_table(:emails) do
primary_key :id
String :authname
String :address
DateTime :created_at
Integer :usage
Bool :primary, default: false
index [:address], unique: true
end
end
end

View File

@ -0,0 +1,14 @@
Sequel.migration do
change do
create_table(:random_sentences) do
primary_key :id
String :author
String :trigger
String :content
Bool :enabled, default: true
DateTime :created_at
index :trigger, unique: true
end
end
end

View File

@ -0,0 +1,10 @@
Sequel.migration do
change do
create_table(:eips) do
primary_key :id
String :author
String :title
DateTime :created_at
end
end
end

View File

@ -1,11 +1,11 @@
class Base
def find_and_exec(name)
def find_and_exec(m, name)
u = User.where(name: name).first
if u
yield u
else
m.reply "no such user"
m.reply "No such user '#{name}'"
end
end
@ -31,7 +31,7 @@ class Base
admin: admin,
groups: [admin ? 'admin' : 'default'])
m.reply "Welcome ##{u.id} #{u.name}"
rescue => err
rescue => _
m.reply "Cannot register #{m.user.authname}"
end
end
@ -46,14 +46,14 @@ class Base
def user_group_ls m, name
cmd_allowed? m
find_and_exec(name) do |u|
find_and_exec(m, name) do |u|
m.reply u.groups.join(', ')
end
end
def user_group_add m, name, group
cmd_allowed? m
find_and_exec(name) do |u|
find_and_exec(m, name) do |u|
u.update(groups: (u.groups + [group]))
m.reply "group #{group} added to #{u.name}"
end
@ -61,7 +61,7 @@ class Base
def user_group_rm m, name, group
cmd_allowed? m
find_and_exec(name) do |u|
find_and_exec(m, name) do |u|
u.update(groups: (u.groups - [group]))
m.reply "group #{group} removed from #{u.name}"
end

View File

@ -1,14 +1,68 @@
class CeQueTuDisNAAucunSens < Botpop::Plugin
include Cinch::Plugin
match(/!?wha+t/i, use_prefix: false, method: :say_random)
match(/^[^!].+$/, use_prefix: false, method: :say_random_sentence)
match(/^!random_sentence register ([^|]+)\|(.+)/, use_prefix: false, method: :register_trigger)
match(/^!random_sentence remove (.+)/, use_prefix: false, method: :remove_trigger)
HELP = ["!what"]
HELP = ["!random_sentence register trigger | content",
"!random_sentence remove trigger" ]
ENABLED = config['enable'].nil? ? false : config['enable']
CONFIG = config
def cmd_allowed? m
return Base.cmd_allowed? m, ["random_sentence"]
end
def say_random_sentence m
trigger = I18n.transliterate(m.message).strip
r = Base::DB[:random_sentences].where(enabled: true).where('? ~* "trigger"', trigger).select(:content).first
return if r.nil?
m.reply r[:content].split(' ').shuffle.join(' ')
end
def say_random m
m.reply %w(ce que tu dis n'a aucun sens).shuffle.join(' ')
end
def register_trigger m, t, c
return if not cmd_allowed? m
t = t.triggerize
begin
Base::DB[:random_sentences].insert(trigger: t,
content: c.strip,
author: m.user.authname,
created_at: Time.now.utc)
m.reply "The trigger \"#{t.strip}\" will raise \"#{c.strip}\""
rescue => _err
m.reply "Error. Cannot register this trigger"
m.reply _err
end
end
def remove_trigger m, t
return if not cmd_allowed? m
t = t.triggerize
n = Base::DB[:random_sentences].where(trigger: t).delete
m.reply "Deleted #{n} trigger"
end
end
class String
def triggerize
t = self.dup
t = I18n.transliterate(t).strip
t = Regexp.quote(t)
t.gsub!(/((a)a+)/i, '\2') # ... i know :(
t.gsub!(/((e)e+)/i, '\2')
t.gsub!(/((i)i+)/i, '\2')
t.gsub!(/((o)o+)/i, '\2')
t.gsub!(/((u)u+)/i, '\2')
t.gsub!(/((y)y+)/i, '\2')
t.gsub!(/([aeiouy])/, '\1+')
# TODO: not only " " but also ponctuation etc.
t = "^(.* )?#{t}( .*)?$"
return t
end
end

12
plugins/dice/Character.rb Normal file
View File

@ -0,0 +1,12 @@
class Character
attr_accessor :carac, :skills, :hp, :classes, :bab
def initialize(str, dex, con, int, wiz, cha, opt={})
@carac = {str: str, dex: dex, con: con, int: int, wiz: wiz, cha: cha}
@skills = {}
@hp = opt[:hp] || nil
@classes = opt[:classes] || {}
@bab = opt[:bab] || [0]
end
end

98
plugins/dice/Dice.rb Normal file
View File

@ -0,0 +1,98 @@
class FrozenDice
attr_reader :min, :max, :values, :nb, :faces
def initialize arg
if arg.is_a? String
v = arg.match(/^(?<nb>\d+)d(?<faces>\d+)$/i)
if v
set_rolldice v
else
raise ArgumentError unless arg.match(/^\d+$/)
set_value arg.to_i
end
elsif arg.is_a? Integer
set_value arg
else
raise ArgumentError
end
end
def throw
@nb.times.map{ rand(@values) }
end
def test
self.throw.inject(&:+)
end
def mean
v = values.to_a
if v.size % 2 == 0
(v[v.size / 2 - 1] + v[v.size / 2]) * 0.5
else
v[v.size / 2]
end
end
private
def set_rolldice v
@nb, @faces = v[:nb].to_i, v[:faces].to_i
@max = @faces
@min = 1
@values = @min..@max
end
def set_value v
@nb = 1
@faces = v
@min = @faces
@max = @faces
@values = @min..@max
end
end
class Dice
attr_accessor :bonus, :dices
def initialize *arg
@dices = []
arg.each do |a1|
a1.gsub!(" ", "")
a1.split(/[+ ]/).each do |a2|
@dices << FrozenDice.new(a2)
end
end
end
def min
@dices.map do |dice|
dice.min
end
end
def mean
@dices.map do |dice|
dice.mean
end
end
def max
@dices.map do |dice|
dice.max
end
end
def throw
@dices.map do |dice|
dice.throw
end
end
def test
@dices.map do |dice|
dice.test
end.inject(&:+)
end
end

12
plugins/dice/Warrior.rb Normal file
View File

@ -0,0 +1,12 @@
require_relative 'Character'
class Warrior < Character
def initialize str, *arg
super(str, 10, 10, 10, 10, 10, *arg)
end
def str; carac[:str]; end
def bstr; (str - 10) / 2; end
end

84
plugins/dice/Weapon.rb Normal file
View File

@ -0,0 +1,84 @@
require_relative 'Dice'
require_relative 'Warrior'
class Weapon
attr_reader :from, :degats, :opt, :bonus
def initialize from, degats, opt, bonus, attack_opt={}
@from = from
@bonus = from.bab.map{|e| e + bonus}
@degats = Dice.new(degats + "+#{(from.bstr * 1.5).ceil}")
@hands = opt[:hands] || 1
@max = attack_opt[:max] || Float::INFINITY
end
def min
@degats.min
end
def max
@degats.max
end
def mean
@degats.mean
end
def test
@degats.test
end
def mean_p(ca=20.0)
d = @degats.mean.inject(&:+)
p(ca).map do |b|
(b * d).round(4)
end
end
def p(ca=20.0)
@bonus.map do |b|
((b + from.bstr) / ca.to_f).round(4)
end
end
def mean_p_total(ca=20.0)
mean_p(ca).inject(&:+).round(4)
end
def to_s(ca=20)
"mean: #{mean} * #{p(ca)} => #{mean_p(ca)} = #{mean_p_total(ca)}"
end
end
if __FILE__ == $0
alteration = 2
taille = -2
bonus = alteration + taille
epees = []
normal = Warrior.new 18, {bab: [7, 1]}
epees << ["normal", Weapon.new(normal, "4d6+2", {hands: 2}, bonus)]
rage = Warrior.new 19+4, {bab: [7, 1]}
epees << ["rage", Weapon.new(rage, "4d6+2", {hands: 2}, bonus)]
fren = Warrior.new 19+6, {bab: [7, 1]}
epees << ["frenesie", Weapon.new(fren, "4d6+2", {hands: 2}, bonus)]
ra_fr = Warrior.new 19+4+6, {bab: [7, 7, 1]}
epees << ["rage+frenesie", Weapon.new(ra_fr, "4d6+2", {hands: 2}, bonus)]
ra_fr_so = Warrior.new 19+6+4, {bab: [7, 7, 1]}
epees << ["rage+frenesie+sorciere", Weapon.new(ra_fr_so, "4d6+2+5+1d6", {hands: 2}, bonus)]
ra_fr_so_buff = Warrior.new 19+6+4+4, {bab: [7, 7, 1]}
epees << ["rage+frenesie+sorciere+taureau+benediction", Weapon.new(ra_fr_so, "4d6+2+5+1d6", {hands: 2}, bonus+1)]
ra_fr_so_buff_char = Warrior.new 19+6+4+4, {bab: [7, 7]}
epees << ["rage+frenesie+sorciere+taureau+benediction+charge", Weapon.new(ra_fr_so, "4d6+2+5+1d6", {hands: 2}, bonus+1+2, {max: 2})]
epees = Hash[epees]
require 'pry'
binding.pry
end

22
plugins/diceroller.rb Normal file
View File

@ -0,0 +1,22 @@
require_relative 'dice/Dice'
require_relative 'dice/Weapon'
require_relative 'dice/Character'
require_relative 'dice/Warrior'
class Diceroller < Botpop::Plugin
include Cinch::Plugin
match(/!roll (.+)/, use_prefix: false, method: :exec_roll)
HELP = ["!roll (d20 ...)"]
ENABLED = config['enable'].nil? ? false : config['enable']
CONFIG = config
CHARACTER = Warrior.new 10, {bab: [0]}
def exec_roll(m, roll)
val = Weapon.new(CHARACTER, roll, {hands: 1}, 0).test
m.reply "Roll ... '#{roll}' ... #{val}"
end
end

35
plugins/eip.rb Normal file
View File

@ -0,0 +1,35 @@
class Eip < Botpop::Plugin
include Cinch::Plugin
match(/!eip add (.*)/, use_prefix: false, method: :exec_add)
match(/!eip ls/, use_prefix: false, method: :exec_ls)
match(/!eip (\d+)/, use_prefix: false, method: :exec_id)
HELP = ["!eip add ...", "!eip ls", "!eip id"]
ENABLED = config['enable'].nil? ? false : config['enable']
CONFIG = config
def exec_add(m, title)
begin
Base::DB[:eips].insert(author: m.user.authname,
title: title,
created_at: Time.now)
m.reply "Ok ! #{title} is a new eip"
rescue
m.reply "Err"
end
end
def exec_id(m, id)
all = Base::DB[:eips].where(id: Integer(id)).first
m.reply all[:title] rescue m.reply("no such id")
end
def exec_ls(m)
all = Base::DB[:eips].limit(3).reverse.all
all.each{|e| m.reply e[:title]}
n = Base::DB[:eips].count
m.reply("There is #{n} elements")
end
end

20
plugins/encrypt.rb Normal file
View File

@ -0,0 +1,20 @@
require 'tor257/core'
require 'base64'
class Encrypt < Botpop::Plugin
include Cinch::Plugin
match(/^!tor257 (c|d) (\w+) (.+)/, use_prefix: false, method: :exec_tor257)
HELP = ["!tor257 <c|d> keyphrase data"]
ENABLED = config['enable'].nil? ? false : config['enable']
CONFIG = config
def exec_tor257 m, type, k, d
d = Base64.decode64(d.strip) if type == 'd'
e = Tor257::Message.new(d).encrypt(Tor257::Key.new(k)).to_s
e = Base64.encode64(e) if type == 'c'
m.reply e
end
end

View File

@ -39,7 +39,7 @@ class IAmAlive < Botpop::Plugin
def react_on_entry m
return if @@mode != :live
e = Entry.where(message: m.message).to_a.map(&:id).map{|x| x+1}
e = Entry.where('LOWER(message) = LOWER(?)', m.message).select(:id).all.map(&:id).map{|x| x+1}
if @@reactivity > rand(1..100)
answer_to(m, e)
end

View File

@ -2,12 +2,30 @@ require 'sequel'
class IAmAlive
class IAAMessage < String
def initialize *arg
super(*arg)
self.strip!
end
end
class Entry < Sequel::Model
def before_create
self.created_at ||= Time.now
self.message.strip!
self.message_origin = self.message
self.message = IAAMessage.new(self.message).to_s
super
end
set_dataset DB[:entries]
def self.anwser(message)
Entry.where('LOWER(message) = LOWER(?)', m.message.to_iaa_message).
select(:id).all.map(&:id).map{|x| x+1}
end
end
end

View File

@ -5,6 +5,7 @@ Sequel.migration do
String :user, null: false
String :channel, null: false
String :message, null: false, text: true
String :message_origin, null: false, text: true
DateTime :created_at
end
end

27
plugins/kick.rb Normal file
View File

@ -0,0 +1,27 @@
#encoding: utf-8
class Kick < Botpop::Plugin
include Cinch::Plugin
match(/!k (.+)/, use_prefix: false, method: :exec_kick)
match(/!kick (.+)/, use_prefix: false, method: :exec_kick)
match(/!k ([^|]+)\|(.+)/, use_prefix: false, method: :exec_kick_message)
match(/!kick ([^|]+)\|(.+)/, use_prefix: false, method: :exec_kick_message)
HELP = ["!kick nickname <message>"]
ENABLED = config['enable'].nil? ? true : config['enable']
CONFIG = config
def exec_kick m, victim
len = CONFIG["list"].length - 1
msg = CONFIG["list"][rand(0..len)]
m.channel.kick(victim, msg)
m.reply "Bye bye " + victim
end
def exec_kick_message m, victim, reason
m.channel.kick(victim, reason)
m.reply "Bye bye " + victim
end
end

51
plugins/ops.rb Normal file
View File

@ -0,0 +1,51 @@
#encoding: utf-8
class Ops < Botpop::Plugin
include Cinch::Plugin
match(/!op/, use_prefix: false, method: :exec_op)
match(/!op (.+)/, use_prefix: false, method: :exec_op_other)
match(/!deop/, use_prefix: false, method: :exec_deop)
match(/!deop (.+)/, use_prefix: false, method: :exec_deop_other)
match(/!v/, use_prefix: false, method: :exec_voice)
match(/!v (.+)/, use_prefix: false, method: :exec_voice_other)
match(/!dv/, use_prefix: false, method: :exec_devoice)
match(/!dv (.+)/, use_prefix: false, method: :exec_devoice_other)
HELP = ["!op <nickname>", "!deop <nickname>"]
ENABLED = config['enable'].nil? ? true : config['enable']
CONFIG = config
def exec_op m
m.channel.op(m.user)
end
def exec_op_other m, other
m.channel.op(other)
end
def exec_deop m
m.channel.deop(m.user)
end
def exec_deop_other m, other
m.channel.deop(other)
end
def exec_voice m
m.channel.voice(m.user)
end
def exec_voice_other m, other
m.channel.voice(other)
end
def exec_devoice m
m.channel.devoice(m.user)
end
def exec_devoice_other m, other
m.channel.devoice(other)
end
end

View File

@ -1,24 +1,43 @@
#encoding: utf-8
class Base < Botpop::Plugin
class Points < Botpop::Plugin
include Cinch::Plugin
include Botpop::Plugin::Database
match(/.*/, use_prefix: false, method: :save_last_user)
match(/!p (\w+)$/, use_prefix: false, method: :add_point_to_last)
match(/!p (\w+) (\w+)$/, use_prefix: false, method: :add_point_to_user)
match(/^!pstats?$/, use_prefix: false, method: :statistics)
match(/^!pstats?u (\w+)$/, use_prefix: false, method: :statistics_for_user)
match(/^!pstats?p (\w+)$/, use_prefix: false, method: :statistics_for_point)
match(/^!p +(\w+)$/, use_prefix: false, method: :add_point_to_last)
match(/^!p +(\w+) +(\w+)$/, use_prefix: false, method: :add_point_to_user)
match(/hei(l|i)/i, use_prefix: false, method: :point_nazi)
HELP = ["!p [type] <to>"]
HELP = ["!p <type> [to]", "!pstats", "!pstatsu <nick>", "!pstatsp <point>"]
ENABLED = config['enable'].nil? ? true : config['enable']
CONFIG = config
if ENABLED
require_relative 'points/PointModel'
end
@@users = {}
@@lock = Mutex.new
def statistics m
ret = Base::DB.fetch("SELECT points.type, COUNT(*) AS nb FROM points GROUP BY points.type ORDER BY nb DESC LIMIT 10;").all.map{|e| e[:type] + "(#{e[:nb]})"}.join(", ")
# data = Base::DB.fetch("SELECT points.type, COUNT(points.*) AS nb FROM points GROUP BY points.type ORDER BY nb DESC LIMIT 10;").all
# data.map!{|e| Base::DB.fetch("SELECT assigned_to FROM points GROUP BY type, assigned_to HAVING type = ? ORDER BY COUNT(*) DESC;", e[:type]).first.merge(e)}
# ret = data.map{|e| e[:type] + "(#{e[:nb]}x #{e[:assigned_to]})"}.join(", ")
m.reply "Top used: #{ret}"
end
def statistics_for_user m, u
ret = Base::DB.fetch("SELECT points.type, COUNT(*) AS nb FROM points WHERE assigned_to = ? GROUP BY points.type ORDER BY COUNT(*) DESC LIMIT 10;", u.downcase).all.map{|e| e[:type] + "(#{e[:nb]})"}.join(", ")
m.reply "User #{u} has: #{ret}"
end
def statistics_for_point m, p
data = Base::DB.fetch("SELECT assigned_to, COUNT(*) AS nb FROM points GROUP BY type, assigned_to HAVING type = ? ORDER BY COUNT(*) DESC LIMIT 10;", p).all
ret = data.map{|e| e[:assigned_to] + "(#{e[:nb]})"}.join(", ")
m.reply "Point #{p}: #{ret}"
end
def save_last_user m
return if m.message.match(/^!p .+$/)
@@lock.lock
@ -29,15 +48,29 @@ class Base < Botpop::Plugin
def add_point_to_last m, type
return if @@users[m.channel.to_s].nil?
nick = @@users[m.channel.to_s]
Point.create({assigned_by: m.user.nick, assigned_to: nick, type: type})
count = Point.where(assigned_to: nick, type: type).count
m.reply "User #{nick} has now #{count} points #{type} !"
count = add_point(m.user.nick, nick, type)
m.reply "#{nick} has now #{count} points #{type} !"
end
def add_point_to_user m, type, nick
Point.create({assigned_by: m.user.nick, assigned_to: nick, type: type})
count = Point.where(assigned_to: nick, type: type).count
m.reply "User #{nick} has now #{count} points #{type} !"
count = add_point(m.user.nick, nick, type)
m.reply "#{nick} has now #{count} points #{type} !"
end
def point_nazi m
nick = m.user.nick
count = add_point("self", nick, "nazi")
m.reply "#{nick} has now #{count} points nazi !" if count % 10 == 0
end
private
def add_point(by, to, type)
to.downcase!
Base::DB[:points].insert({assigned_by: by,
assigned_to: to,
type: type,
created_at: Time.now})
Base::DB[:points].where(assigned_to: to, type: type).count
end
end

View File

@ -1,3 +1,5 @@
require 'date'
class Puppet < Botpop::Plugin
include Cinch::Plugin
@ -5,7 +7,21 @@ class Puppet < Botpop::Plugin
match(/^!join (\#\w+)/, use_prefix: false, method: :join)
match(/^!part (\#\w+)/, use_prefix: false, method: :part)
HELP = ["!pm <#chat/nick> <message>", "!join <#chan>", "!part <#chan>"]
# Email handlement
EMAIL = '[[:alnum:]\.\-_]{1,64}@[[:alnum:]\.\-_]{1,64}'
NICK = '\w+'
# Registration of an email address - association with authname
match(/^!mail register (#{EMAIL})$/, use_prefix: false, method: :register)
match(/^!mail primary (#{EMAIL})$/, use_prefix: false, method: :make_primary)
# Send email to user through its nickname (not safe)
match(/^!(mail )?(let|send) (#{NICK}) (.+)/, use_prefix: false, method: :let)
# Send email to user through one of its emails (safe)
match(/^!(mail )?(let|send) (#{EMAIL}) (.+)/, use_prefix: false, method: :let)
# Read email (based on nickname, authname, and emails)
match(/^!(mail )?r(ead)?$/, use_prefix: false, method: :read)
HELP = ["!pm <#chat/nick> <message>", "!join <#chan>", "!part <#chan>", "!let <to> msg", "!read"] +
["!mail read", "!mail send/let <...>", "!mail register address"]
ENABLED = config['enable'].nil? ? false : config['enable']
CONFIG = config
@ -25,14 +41,79 @@ class Puppet < Botpop::Plugin
Channel(chan).part
end
def register m, email
begin
Base::DB[:emails].insert(authname: m.user.authname,
address: email,
created_at: Time.now.utc,
usage: 0)
rescue => _
return m.reply "Error, cannot register this email !"
end
return m.reply "Email #{email} registered for you, #{m.user.authname}"
end
def make_primary m, email
a = get_addresses(m.user).where(address: email)
return m.reply "No your email #{email}" if a.first.nil?
get_addresses(m.user).update(primary: false)
a.update(primary: true)
m.reply "Your primary email #{m.user.nick} is now #{email}"
end
def let m, _, _, to, msg
log "New message addressed to #{to} to send"
# insert new message in database
from = Base::DB[:emails].where(authname: m.user.authname, primary: true).select(:address).first
from = from && from[:address] || m.user.nick
Base::DB[:messages].insert(author: from,
dest: to,
content: msg.strip,
created_at: Time.now,
read_at: nil)
Base::DB[:emails].where(address: to).update('usage = usage+1')
end
def read m, _
msg = get_messages(m.user).first
if msg.nil?
send_privmsg_to_user m.user, "No message."
return
end
Base::DB[:messages].where(id: msg[:id]).update(read_at: Time.now)
date = msg[:created_at]
if Date.parse(Time.now.to_s) == Date.parse(date.to_s)
date = date.strftime("%H:%M:%S")
else
date = date.strftime("%B, %d at %H:%M:%S")
end
send_privmsg_to_user m.user, "##{msg[:id]}# #{date} -- from #{msg[:author]}"
send_privmsg_to_user m.user, msg[:content]
end
listen_to :join, method: :bip_on_join
def bip_on_join m
nb = Base::DB[:messages].where(dest: m.user.nick, read_at: nil).count
send_privmsg_to_user m.user, "#{m.user.nick}: You have #{nb} message unread." unless nb.zero?
end
private
def send_privmsg_to_channel chan, msg
Channel(chan).send(msg)
Channel(chan).send(msg.strip)
end
def send_privmsg_to_user user, msg
User(user).send(msg)
User(user).send(msg.strip)
end
def get_messages user
emails = Base::DB[:emails].where(authname: user.authname).select(:address).all.map(&:values).flatten
Base::DB[:messages].where(dest: [user.nick, user.authname] + emails).where(read_at: nil)
end
def get_addresses user
Base::DB[:emails].where(authname: user.authname)
end
public
end

42
plugins/root_me.rb Normal file
View File

@ -0,0 +1,42 @@
require "base64"
class RootMe < Botpop::Plugin
include Cinch::Plugin
FloatRegexp = "\d+(\.\d+)?"
match(/!ep1 (\w+)/, use_prefix: false, method: :start_ep1)
match(/!ep2 (\w+)/, use_prefix: false, method: :start_ep2)
match(/^(#{FloatRegexp}) ?\/ ?(#{FloatRegexp})$/, use_prefix: false, method: :play_ep1)
match(/^(\d+) ?\/ ?(\d+)$/, use_prefix: false, method: :play_ep1)
match(/^(\w+)$/, use_prefix: false, method: :play_ep2)
ENABLED = config['enable'].nil? ? false : config['enable']
CONFIG = config
def start_ep1 m, botname
bot = User(botname)
bot.send "!ep1"
end
def start_ep2 m, botname
bot = User(botname)
bot.send "!ep2"
end
def play_ep1 m, n1, n2
r = n1.to_f**(0.5) * n2.to_f
str = "!ep1 -rep #{r.round 2}"
puts str
m.reply str
# response will be logged by the bot, check the log
end
def play_ep2 m, b64
r = Base64.decode64(b64)
str = "!ep2 -rep #{r}"
puts str
m.reply str
# response will be logged by the bot, check the log
end
end