Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Bugfixes and updating, added fib function to plugin_calc

  • Loading branch information...
commit 3a40ac9aef5a70ee7993d3dd376634f8e5e30770 1 parent 4b7942c
Anastasia Gornostaeva authored
View
2  Makefile.sulci
@@ -6,7 +6,7 @@ SOURCES := common.ml config.ml version.ml hooks.ml lang.ml \
plugin_weather.ml plugin_google.ml plugin_userinfo.ml \
plugin_roulette.ml plugin_currency.ml \
plugin_admin.ml plugin_vocabulary.ml \
- pcalc.mly pcalc_lexer.mll \
+ math.ml pcalc.mly pcalc_lexer.mll \
icalc.mly icalc_lexer.ml plugin_calc.ml \
plugin_markov.ml plugin_misc.ml \
plugin_globalstats.ml plugin_tld.ml \
View
11 hooks.ml
@@ -39,10 +39,19 @@ let catchset = ref []
(* bad place here, but unfortunatelly... *)
module Nicks = Map.Make(Id)
+type participant_t = {
+ jid: string;
+ status: string;
+ show: string;
+ role: string;
+ orig_nick: string;
+ affiliation: string
+}
+
type groupchat_t = {
mynick: string;
lang: string;
- nicks: string Nicks.t;
+ nicks: participant_t Nicks.t;
}
module GroupchatMap = Map.Make(Id)
View
16 icalc.mly
@@ -1,19 +1,13 @@
%{
+(* *)
+(* (c) 2004, Anastasia Gornostaeva. <ermine@ermine.pp.ru> *)
+(* *)
+
open Printf
+open Math
let var_table = Hashtbl.create 16
-let fact x =
- if x > 174.0 then failwith "Многовато... :("
- else if x -. floor x <> 0.0 then
- failwith "Не, я не умею вычислять факториал нецелых чисел :("
- else
- let rec f y acc =
- if y <= 0.0 then acc
- else f (y-. 1.) (y *. acc)
- in
- f x 1.
-
%}
%token <float> NUM
View
1  icalc_lexer.mll
@@ -20,6 +20,7 @@
("log10", log10);
("exp", exp);
("sqrt", sqrt);
+ ("fib", Math.fib)
]
}
View
BIN  lang/en.htbl
Binary file not shown
View
6 lang/en.msg
@@ -1,7 +1,10 @@
muc_log_join %s has become available
muc_log_leave %s has left
+muv_log_leave_reason %s has left: %s
muc_log_kick %s has been kicked
+muc_log_kick_reason %s has been kicked: %s
muc_log_ban %s has been banned
+muc_log_ban_reason %s has been banned: %s
muc_log_change_nick %s is now known as %s
plugin_calc_not_parsed I dont understand.
plugin_cakc_empty_command What?
@@ -40,3 +43,6 @@ plugin_globalstats_stats_error It seems that server does not support stats
plugin_google_invalid_syntax hm?
plugin_google_not_found Not found :(
plugin_google_adv_invalid_syntax He-he! You have not guessed the proper syntax
+plugin_calc_number_too_big Too big number... :(
+plugin_calc_cannot_float_fact No, I don't know how to calculate float factorial :(
+plugin_calc_negative_number Impossible..
View
BIN  lang/ru.htbl
Binary file not shown
View
8 lang/ru.msg
@@ -1,7 +1,10 @@
muc_log_join %s появился в конференции
-muc_log_leave %s удалился из конференции
+muc_log_leave %s покинул конференцию
+muc_log_leave_reason %s покинул конференцию: %s
muc_log_kick %s кикнули из конференции
+muc_log_kick_reason %s кикнули из конференции: %s
muc_log_ban %s забанён
+muc_log_ban_reason %s забанён: %s
muc_log_change_nick %s переименовался в %s
plugin_calc_not_parsed что это было?!
plugin_calc_empty_command ась?
@@ -40,3 +43,6 @@ plugin_globalstats_stats_error Скорее всего, сервер не п
plugin_google_invalid_syntax ась?
plugin_google_not_found Не нашел :(
plugin_google_adv_invalid_syntax гы! Не угадал синтаксис.
+plugin_calc_number_too_big Многовато... :(
+plugin_calc_cannot_float_fact Не, я не умею вычислять факториал нецелых чисел :(
+plugin_calc_negative_number Так не бывает.
View
127 muc.ml
@@ -10,10 +10,10 @@ open Unix
open Pcre
type muc_event = | MUC_join of string
- | MUC_leave of string
+ | MUC_leave of string * string
| MUC_change_nick of string * string * string
- | MUC_kick of string
- | MUC_ban of string
+ | MUC_kick of string * string
+ | MUC_ban of string * string
| MUC_presence
| MUC_topic of string
| MUC_message
@@ -153,19 +153,23 @@ let log_presence room event lang =
let text = match event with
| MUC_join user ->
Lang.get_msg ~lang "muc_log_join" [user]
- (* user ^ " появился в конференции" *)
- | MUC_leave user ->
- Lang.get_msg ~lang "muc_log_leave" [user]
- (* user ^ " исчез из конференции" *)
- | MUC_kick user ->
- Lang.get_msg ~lang "muc_log_kick" [user]
- (* user ^ " был выкинут из конференции" *)
- | MUC_ban user ->
- Lang.get_msg ~lang "muc_log_ban" [user]
- (* user ^ "был забанен" *)
+ | MUC_leave (user, reason) ->
+ if reason = "" then
+ Lang.get_msg ~lang "muc_log_leave" [user]
+ else
+ Lang.get_msg ~lang "muc_log_leave_reason" [user; reason]
+ | MUC_kick (user, reason) ->
+ if reason = "" then
+ Lang.get_msg ~lang "muc_log_kick" [user]
+ else
+ Lang.get_msg ~lang "muc_log_kick_reason" [user; reason]
+ | MUC_ban (user, reason) ->
+ if reason = "" then
+ Lang.get_msg ~lang "muc_log_ban" [user]
+ else
+ Lang.get_msg ~lang "muc_log_ban_reason" [user; reason]
| MUC_change_nick (newnick, user, orignick) ->
Lang.get_msg ~lang "muc_log_change_nick" [user; newnick]
- (* user ^ "переименовался в " ^ newnick *)
| _ -> ""
in
if text <> "" then
@@ -177,54 +181,77 @@ let process_presence xml out =
let user = get_resource from in
let room = get_bare_jid from in
let room_env = GroupchatMap.find room !groupchats in
+ let x = List.find (function
+ | Xmlelement ("x", attrs, _) ->
+ if (try List.assoc "xmlns" attrs with _ -> "")=
+ "http://jabber.org/protocol/muc#user"
+ then true else false
+ | _ -> false
+ ) (Xml.get_subels xml) in
let event = match safe_get_attr_s xml "type" with
| "" ->
- if not (Nicks.mem user room_env.nicks) then begin
- groupchats := GroupchatMap.add room
- {room_env with nicks = Nicks.add user user room_env.nicks}
- !groupchats;
- MUC_join user
- end
- else
- MUC_ignore
+ let status = try get_cdata xml ~path:["status"] with _ -> "" in
+ let show = try get_cdata xml ~path:["show"] with _ -> "available" in
+ if not (Nicks.mem user room_env.nicks) then begin
+ let item = { jid = (try get_attr_s x ~path:["item"] "jid"
+ with _ -> "");
+ role = (try get_attr_s x ~path:["item"] "role"
+ with _ -> "");
+ affiliation = (try get_attr_s x
+ ~path:["item"] "affiliation"
+ with _ -> "");
+ status = status;
+ show = show;
+ orig_nick = user
+ } in
+ groupchats := GroupchatMap.add room
+ {room_env with nicks = Nicks.add user item
+ room_env.nicks} !groupchats;
+ MUC_join user
+ end
+ else
+ let item = Nicks.find user room_env.nicks in
+ groupchats := GroupchatMap.add room
+ {room_env with
+ nicks = Nicks.add user
+ {item with status = status; show = show;}
+ room_env.nicks} !groupchats;
+ MUC_ignore
| "unavailable" ->
- let x =
- List.find
- (function
- | Xmlelement ("x", attrs, _) ->
- if (try List.assoc "xmlns" attrs with _ -> "")=
- "http://jabber.org/protocol/muc#user"
- then true else false
- | _ -> false
- ) (Xml.get_subels xml) in
- (match safe_get_attr_s x ~path:["status"] "code" with
- | "303" -> (* /nick *)
- let newnick =
- get_attr_s xml ~path:["x"; "item"] "nick" in
- let orignick = Nicks.find user room_env.nicks in
- groupchats := GroupchatMap.add room
- {room_env with nicks =
- Nicks.add newnick orignick
- (Nicks.remove user room_env.nicks)}
- !groupchats;
- MUC_change_nick (newnick, user, orignick)
- | "307" -> (* /kick *)
+ (match safe_get_attr_s x ~path:["status"] "code" with
+ | "303" -> (* /nick *)
+ let newnick =
+ get_attr_s xml ~path:["x"; "item"] "nick" in
+ let item = Nicks.find user room_env.nicks in
+ groupchats := GroupchatMap.add room
+ {room_env with nicks =
+ Nicks.add newnick item
+ (Nicks.remove user room_env.nicks)}
+ !groupchats;
+ MUC_change_nick (newnick, user, item.orig_nick)
+ | "307" -> (* /kick *)
+ let reason =
+ try get_cdata ~path:["reason"] x with _ -> "" in
groupchats := GroupchatMap.add room
{room_env with nicks =
Nicks.remove user room_env.nicks} !groupchats;
- MUC_kick user
- | "301" -> (* /ban *)
+ MUC_kick (user, reason)
+ | "301" -> (* /ban *)
+ let reason =
+ try get_cdata ~path:["reason"] x with _ -> "" in
groupchats := GroupchatMap.add room
{room_env with nicks =
Nicks.remove user room_env.nicks} !groupchats;
- MUC_ban user
- | "321" (* non-member *)
- | _ ->
+ MUC_ban (user, reason)
+ | "321" (* non-member *)
+ | _ ->
+ let reason =
+ try get_cdata ~path:["status"] xml with _ -> "" in
groupchats := GroupchatMap.add room
{room_env with nicks =
Nicks.remove user room_env.nicks} !groupchats;
- MUC_leave user
- )
+ MUC_leave (user, reason)
+ )
| _ -> MUC_ignore
in
log_presence room event room_env.lang
View
3  pcalc.mly
@@ -5,7 +5,7 @@
%token <float> NUM
%token PLUS MINUS MUL DIVIDE CARET UMINUS
%token COS SIN ACOS ASIN COSH SINH TAN ATAN TANH ATAN2 CEIL FLOOR
-%token LOG LOG10 EXP SQRT
+%token LOG LOG10 EXP SQRT FIB
%token MAX_FLOAT PI
%token EOL
@@ -40,6 +40,7 @@ expr:
| expr TANH { tanh $1 }
| expr CEIL { ceil $1 }
| expr FLOOR { floor $1 }
+ | expr FIB { Math.fib $1 }
| MAX_FLOAT { max_float }
| PI { 4. *. (atan (1./.2.) +. atan (1./.3.)) }
;
View
1  pcalc_lexer.mll
@@ -33,6 +33,7 @@ rule token = parse
| "tanh" { TANH }
| "ceil" { CEIL }
| "floor" { FLOOR }
+ | "fib" { FIB }
| "max_float" { MAX_FLOAT }
| ['p' 'P'] ['i' 'I'] { PI }
| _ { token lexbuf }
View
22 plugin_calc.ml
@@ -1,4 +1,9 @@
+(* *)
+(* (c) 2004, Anastasia Gornostaeva. <ermine@ermine.pp.ru> *)
+(* *)
+
open Common
+open Math
let pcalc text xml out =
if text <> "" then
@@ -6,8 +11,15 @@ let pcalc text xml out =
try
let lexbuf = Lexing.from_string text in
Pcalc.line Pcalc_lexer.token lexbuf
- with exn ->
- Lang.get_msg ~xml "plugin_calc_not_parsed" []
+ with
+ | MathNumberTooBig ->
+ Lang.get_msg ~xml "plugin_calc_number_too_big" []
+ | MathCannotFloatFact ->
+ Lang.get_msg ~xml "plugin_calc_cannot_float_fact" []
+ | MathNegNumber ->
+ Lang.get_msg ~xml "plugin_calc_negative_number" []
+ | _ ->
+ Lang.get_msg ~xml "plugin_calc_not_parsed" []
in
out (make_msg xml reply)
else
@@ -20,6 +32,12 @@ let icalc text xml out =
let lexbuf = Lexing.from_string text in
Icalc.line Icalc_lexer.token lexbuf
with
+ | MathNumberTooBig ->
+ Lang.get_msg ~xml "plugin_calc_number_too_big" []
+ | MathCannotFloatFact ->
+ Lang.get_msg ~xml "plugin_calc_cannot_float_fact" []
+ | MathNegNumber ->
+ Lang.get_msg ~xml "plugin_calc_negative_number" []
| Failure err ->
err
| exn ->
View
3  plugin_markov.ml
@@ -189,7 +189,8 @@ let markov_count text xml out =
let markov_top text xml out =
let vm = compile_simple db
- "SELECT word1, word2, counter FROM words WHERE word1!='' AND word2!='' ORDER BY counter DESC LIMIT 10"
+ "SELECT word1, word2, counter FROM words WHERE word1!='' AND word2!='' \
+ ORDER BY counter DESC LIMIT 10"
in
let rec cycle () =
try
View
21 plugin_userinfo.ml
@@ -147,7 +147,28 @@ let time text xml out =
Hooks.register_handle (Hooks.Id (id, proc));
out (iq_query ~id ~to_:(get_attr_s xml "from") "jabber:iq:time")
+let status text xml out =
+ if safe_get_attr_s xml "type" = "groupchat" then
+ let from = get_attr_s xml "from" in
+ let room = get_bare_jid from in
+ let nick =
+ if text = "" then
+ get_resource from
+ else
+ text
+ in
+ try
+ let item =
+ Nicks.find nick (GroupchatMap.find room !groupchats).nicks in
+ if item.status = "" then
+ out (make_msg xml ("[" ^ item.show ^ "]"))
+ else
+ out (make_msg xml (item.status ^ " [" ^ item.show ^ "]"))
+ with _ ->
+ out (make_msg xml "Whose status?")
+
let _ =
register_handle (Command ("version", version));
register_handle (Command ("idle", idle));
register_handle (Command ("time", time));
+ register_handle (Command ("status", status))
View
2  version.ml
@@ -2,4 +2,4 @@
(* (c) 2004, Anastasia Gornostaeva. <ermine@ermine.pp.ru> *)
(* *)
-let version="0.2"
+let version="0.3"
Please sign in to comment.
Something went wrong with that request. Please try again.