izbot.pro 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808
  1. :- dynamic irc_input1/4.
  2. ?- consult('config.pro').
  3. ?- consult('bot.pro').
  4. ?- consult('bothelp.pro').
  5. % ?- consult('dbase.pro').
  6. % ?- include('7cardstud.pro').
  7. reload_config :-
  8. write('++ reloading config ++'), nl,
  9. reconsult('izbot.pro'),
  10. !.
  11. read_sock(Str, []) :- at_end_of_stream(Str),!.
  12. read_sock(Str, [Byte|Bytelist]) :-
  13. get_byte(Str, Byte),
  14. read_sock(Str, Bytelist).
  15. read_line(Str, []) :- at_end_of_stream(Str),!.
  16. read_line(Str, [C|Cl]) :-
  17. get_byte(Str, C),
  18. !,
  19. C > 13,
  20. read_line(Str, Cl).
  21. irc_recv(Line) :-
  22. sock(R, _),
  23. read_line_to_codes(R, Line),
  24. !,Line \= end_of_file.
  25. /* read_line(R, Line). */
  26. putstring([]) :- nl.
  27. putstring([A | Rest]) :-
  28. atom(A),
  29. tab(1),write(A),
  30. putstring(Rest).
  31. putstring([A | Rest]) :-
  32. not(atom(A)),
  33. put(A), putstring(Rest).
  34. writestr([]) :- nl.
  35. writestr([A | Rest]) :- write(A), putstring(Rest).
  36. putstring(Stream, []) :- nl(Stream).
  37. putstring(Stream, [A | Rest]) :-
  38. atom(A),
  39. tab(Stream, 1), write(Stream, A),
  40. putstring(Stream, Rest).
  41. putstring(Stream, [A | Rest]) :-
  42. not(atom(A)),
  43. put(Stream, A), putstring(Stream, Rest).
  44. putstringRaw(Stream, []) :- nl(Stream).
  45. putstringRaw(Stream, [A | Rest]) :-
  46. atom(A),
  47. write(Stream, A),
  48. putstringRaw(Stream, Rest).
  49. putstringRaw(Stream, [A | Rest]) :-
  50. not(atom(A)),
  51. put(Stream, A), putstringRaw(Stream, Rest).
  52. irc_send(Msg) :-
  53. sock(_, W),
  54. putstring(W, Msg),
  55. flush_output(W).
  56. irc_sendRaw(Msg) :-
  57. sock(_, W),
  58. putstringRaw(W, Msg),
  59. flush_output(W).
  60. irc_nick(Nick) :-
  61. append("NICK ", Nick, S),
  62. irc_send(S).
  63. irc_user(Nick, Mode, RealName) :-
  64. append("USER ", Nick, S),
  65. append(S, " ", T),
  66. append(T, Mode, U),
  67. append(U, " * ", V),
  68. append(V, RealName, W),
  69. irc_send(W).
  70. irc_join(Chan) :-
  71. append("JOIN ", Chan, S),
  72. irc_send(S).
  73. irc_quit :-
  74. irc_send("QUIT").
  75. irc_pong(Seq) :-
  76. atom_codes(Seq, SS),
  77. append("PONG ", SS, X),
  78. irc_send(X).
  79. irc_privmsg(To, Msg) :-
  80. atom_codes(To, T),
  81. append("PRIVMSG ", T, X),
  82. append(X, " ", Y),
  83. flatten(Msg, M),
  84. append(Y, M, Z),
  85. irc_send(Z), !.
  86. irc_privmsgRaw(To, Msg) :-
  87. atom_codes(To, T),
  88. append("PRIVMSG ", T, X),
  89. append(X, " ", Y),
  90. flatten(Msg, M),
  91. write(M),nl,
  92. append(Y, M, Z),
  93. write(Z),nl,
  94. irc_sendRaw(Z), !.
  95. irc_notice(To, Msg) :-
  96. atom_codes(To, T),
  97. append("NOTICE ", T, X),
  98. append(X, " ", Y),
  99. flatten(Msg, M),
  100. append(Y, M, Z),
  101. irc_send(Z), !.
  102. irc_voice(User,Channel) :-
  103. atom_codes(User, U),
  104. atom_codes(Channel, C),
  105. append("MODE ", C, W),
  106. append(W, " +v ", X),
  107. append(X, U, Y),
  108. irc_send(Y).
  109. irc_mute(User,Channel) :-
  110. atom_codes(User, U),
  111. atom_codes(Channel, C),
  112. append("MODE ", C, W),
  113. append(W, " -v ", X),
  114. append(X, U, Y),
  115. irc_send(Y).
  116. irc_kick(User,Channel,Reason) :-
  117. atom_codes(User, U),
  118. atom_codes(Channel, C),
  119. atom_codes(Reason, R),
  120. append("KICK ", C, W),
  121. append(W, " ", X),
  122. append(X, U, Y),
  123. append(Y, " ", Z),
  124. append(Z, R, A),
  125. irc_send(A).
  126. irc_connect(Server, Port) :-
  127. putstring("connecting...\n"),
  128. tcp_socket(Socket),
  129. tcp_connect(Socket, Server:Port),
  130. tcp_open_socket(Socket, Rs, Ws),
  131. asserta(sock(Rs, Ws)),
  132. asserta(sock(Socket)),
  133. asserta(connected(true)),
  134. putstring("connected\n")
  135. .
  136. irc_disconnect :-
  137. sock(R, W),
  138. sock(S),
  139. retract(sock(R,W)),
  140. close(R), close(W),
  141. tcp_close_socket(S),
  142. putstring("disconnected\n"),!
  143. .
  144. /* this is the main rule that starts the bot. */
  145. irc_bot :-
  146. write(starting),nl,
  147. asserta(app_running(true)),
  148. assertz(kudos(_, 0)),
  149. config_host(Host, Port),
  150. config_owner(Owner),
  151. config_botname(Name),
  152. irc_connect(Host, Port),
  153. irc_nick(Name),
  154. irc_user(Name, "0", Owner),
  155. /* write(sleeping),nl,
  156. sleep(2),
  157. write(awake),nl,*/
  158. irc_readloop,
  159. irc_quit,
  160. irc_disconnect.
  161. prefix(P,L) :- append(P,_,L).
  162. suffix(S,L) :- append(_,S,L).
  163. sublist(SubL,L) :- suffix(S,L), prefix(SubL,S).
  164. first(List,Elem) :- nth0(0,List,Elem).
  165. % ignore jobot
  166. irc_input(['Jobot', _, _], _, _, _).
  167. % log everything
  168. irc_input([From, _,_], 'NOTICE', ['Izbot-0001'], ['remind', To | Msg]) :- !,
  169. concat_atom(Msg, M),
  170. create_reminder(To, From, M),
  171. irc_privmsg(From, 'sure thing'),
  172. write('--reminder-- : '), write(To), nl,
  173. !.
  174. irc_input(_, 'NOTICE', ['Izbot-0001'], ['kudos?', Nick|_]) :- !,
  175. atom_codes(Nick, K),
  176. write(' debug 1 '),
  177. kudos(Nick, Num),
  178. write(Num),nl,
  179. atom_codes(Num, N),
  180. append(K, " currently has ", A),
  181. append(A, N, B),
  182. append(B, " Kudos.", C),
  183. config_channel(Channel),
  184. irc_privmsg(Channel, C),
  185. write('--notice-- kudos? : '), write(Nick), nl,
  186. !.
  187. irc_input(_, 'NOTICE', ['Izbot-0001'], ['kudos', Num, Nick | Reason]) :-
  188. Num =< 42,
  189. Num > 0,
  190. atom_codes(Num, N),
  191. atom_codes(Nick, K),
  192. give_kudos(Nick, Num),
  193. append(K, " was given ", A),
  194. append(A, N, B),
  195. append(B, " Kudos.", C),
  196. config_channel(Channel),
  197. irc_privmsg(Channel, C),
  198. write('--notice-- kudos given'), nl,
  199. !.
  200. irc_input(_, 'NOTICE', ['Izbot-0001'], ['kudos', Num, Nick | Reason]) :-
  201. atom_codes(Num, N),
  202. atom_codes(Nick, K),
  203. append(N, " is a rediculous number of Kudos to give ", A),
  204. append(A, K, B),
  205. append(B, ".", C),
  206. config_channel(Channel),
  207. irc_privmsg(Channel, C),
  208. write('--notice-- kudos give fail'), nl,
  209. !.
  210. irc_input([From,_,_], 'PRIVMSG', _, ['izbot', 'help'|_]) :-
  211. irc_send_help(From), !.
  212. irc_input(['Izzy'|_], 'PRIVMSG', _, ['izbot','kick', Nick, 'because' |Reason]) :-
  213. write('kick'),
  214. atomic_list_concat(Reason, ' ', X),
  215. config_channel(Channel),
  216. irc_kick(Nick, Channel, X), !.
  217. /*
  218. irc_input(['Mal'|_], 'PRIVMSG', _, ['izbot','kick', Nick, 'because' |Reason]) :-
  219. write('kick'),
  220. atomic_list_concat(Reason, ' ', X),
  221. irc_kick(Nick, '#ministryofsillywalks', X), !.
  222. */
  223. irc_input([Nick|_], 'PRIVMSG', _, Text) :- fail,
  224. atom_codes(X, "-_-"),
  225. member(X, Text),
  226. write('-- -- kick --'),
  227. config_channel(Channel),
  228. irc_kick(Nick, Channel, 'That is a lame smiley. Do not use it.'), !.
  229. irc_input1([Nick|_], 'PRIVMSG', _, ['postfix'|Text]) :-
  230. write('-- postfix --'),nl,
  231. postfilter(Text, Codes),
  232. write(Codes),nl,!,
  233. asserta(postfix_lastnick(Nick)),
  234. postfixer(Codes, R1, []),!,
  235. write(['after postfixer', R1]),nl,
  236. number(R1),
  237. atom_number(Result, R1),
  238. write(['result: ',Result]),nl,
  239. config_channel(Channel),
  240. irc_privmsgRaw(Channel, [Nick, ', ', Result]),
  241. write('done'),nl,!.
  242. re_postfilter_num([N|R]) --> 're_09_.-'(N), re_postfilter_num(R).
  243. re_postfilter_num([N]) --> 're_09_.-'(N).
  244. 're_09_.-'(X) --> [X],{char_type(X, digit);X=46;X=45}.
  245. /*
  246. 're_azAZ_-.' --> [X],{char_type(X, csym);X=46;X=45}.
  247. 're_azAZ_-' --> [X],{char_type(X, csym);X=45}.
  248. */
  249. postfilter(['+'|T], ['+'|U]) :- postfilter(T, U).
  250. postfilter(['-'|T], ['-'|U]) :- postfilter(T, U).
  251. postfilter(['*'|T], ['*'|U]) :- postfilter(T, U).
  252. postfilter(['/'|T], ['/'|U]) :- postfilter(T, U).
  253. postfilter(['^'|T], ['^'|U]) :- postfilter(T, U).
  254. postfilter(['mod'|T], ['mod'|U]) :- postfilter(T, U).
  255. postfilter(['ln'|T], ['ln'|U]) :- postfilter(T, U).
  256. postfilter(['e'|T], [2.718281828|U]) :- postfilter(T, U).
  257. postfilter(['pi'|T], [3.141592653589793238462|U]) :- postfilter(T, U).
  258. postfilter([H|T], [O|U]) :- atom_codes(H, C), re_postfilter_num(X, C, Rest),!, Rest = [], number_codes(O, X), postfilter(T, U). % number(H), term_to_atom(O, H), postfilter(T, U).
  259. postfilter([W|T], U) :- write('bad postfix'),nl,config_channel(Channel),irc_privmsg(Channel, ['wtf is ', W]), postfilter(T, U).
  260. postfilter([], []).
  261. postfixer(['+'|T], R, [A, B|S]) :-
  262. write('+'),
  263. R1 is A + B,
  264. postfixer(T, R, [R1|S]).
  265. postfixer(['*'|T], R, [A, B|S]) :-
  266. write('*'),
  267. R1 is A * B,
  268. postfixer(T, R, [R1|S]).
  269. postfixer(['/'|T], R, [A, B|S]) :-
  270. write('/'),
  271. A \= 0, B \= 0,
  272. R1 is A / B,
  273. postfixer(T, R, [R1|S]).
  274. postfixer(['/'|T], R, [A, B|S]) :-
  275. write('-00/-kick-'),nl,
  276. postfix_lastnick(Nick),write(Nick),
  277. config_channel(Channel),
  278. irc_privmsg(Channel, ['postfix = fuck you']),
  279. irc_kick(Nick, Channel, 'Nice try; you fail').
  280. postfixer(['-'|T], R, [A, B|S]) :-
  281. write('-'),
  282. R1 is A - B,
  283. postfixer(T, R, [R1|S]).
  284. postfixer(['^'|T], R, [A, B|S]) :-
  285. write('^'),
  286. R1 is A ** B,
  287. postfixer(T, R, [R1|S]).
  288. postfixer(['mod'|T], R, [A, B|S]) :-
  289. write('mod'),
  290. R1 is B mod A,
  291. postfixer(T, R, [R1|S]).
  292. postfixer(['ln'|T], R, [A|S]) :-
  293. write('ln'),
  294. R1 is log(A),
  295. postfixer(T, R, [R1|S]).
  296. postfixer([N|T], R, S) :-
  297. write('#'),
  298. postfixer(T, R, [N|S]).
  299. postfixer([], R, [R]) :- write('here'),nl.
  300. /* postfixer([], X, Y) :- write(['postfix -- non-empty stack error', X, Y]). */
  301. irc_input(['Izzy'|_], 'PRIVMSG', [From], ['mute', Name|_]) :-
  302. write('-- mute -- '), write(Name),nl,
  303. irc_mute(Name,From), !.
  304. irc_input(['Izzy',_,_], 'PRIVMSG', [From], ['unmute', Name|_]) :-
  305. irc_voice(Name,From), !.
  306. irc_input1(_, 'PING', _, [D]) :-
  307. write('--pong-- '), write(D), putstring("\n"),
  308. irc_pong(D), !.
  309. irc_input(_, 'PRIVMSG', [From], Msg) :-
  310. /* write('--privmsg-- '), write(From), nl, */
  311. member('Izbot...?', Msg),
  312. irc_privmsg(From, "hello back to you. ( Jobot is a tosser. )"), !.
  313. irc_input1(_, 'NOTICE', [To], Msg) :-
  314. To = 'Izbot-0001',
  315. prefix(['reload', 'config'], Msg),
  316. reload_config,!, fail.
  317. irc_input1(['Izzy',_,_], 'NOTICE', [To], Msg) :-
  318. To = 'Izbot-0001',
  319. prefix(['go', 'away','password'], Msg),
  320. config_channel(Channel),
  321. irc_privmsg(Channel, ['goodbye, ','everyone.']),
  322. irc_quit,
  323. retract(app_running(true)),!, fail.
  324. irc_input1(['Izzy',_,_], _, _, Msg) :-
  325. prefix(['izbot', 'get', 'lost'], Msg);
  326. prefix(['get', 'lost', 'izbot'], Msg),
  327. config_channel(Channel),
  328. irc_privmsg(Channel, ['goodbye, ','everyone.']),
  329. irc_quit,
  330. retract(app_running(true)),!, fail.
  331. irc_input1(_, 'NOTICE' , [To], Msg) :-
  332. To = 'Izbot-0001',
  333. prefix(['say'], Msg),
  334. Msg = [_|X],
  335. write('--notice-- say '), nl,
  336. config_channel(Channel),
  337. irc_privmsg(Channel, X),
  338. !,fail.
  339. /*:staticfree.foonetic.net 001 Izbot-0001 :Welcome to the Foonetic IRC Network Izbot-0001!Izbot-0001@hostname.com*/
  340. /* :daemonic.foonetic.net 353 Izbot-0001 = #channelname :Izbot-0001 &mo +Krisx &Liberum_Vir &Izzy */
  341. /*
  342. irc_input('353', [Me, _, Channel, _ |Names) :-
  343. map_list(add_nick(),
  344. write('-- added nicks: '), putstring([Me|Names]),nl,
  345. !.
  346. add_nick(Nick) :-
  347. nicklist
  348. */
  349. irc_input(_, 1, _, _) :-
  350. write(' -- joi'),
  351. config_channel(Channel),
  352. irc_join(Channel),
  353. write('ned -1-'),!.
  354. irc_input(_, '001', _, _) :-
  355. write(' -- joi'),
  356. config_channel(Channel),
  357. irc_join(Channel),
  358. write('ned -2-'),!.
  359. irc_input(_, _, _, _) :- /*
  360. write('unknown message recieved: '),
  361. writestr(MSG),
  362. tab(2),
  363. writestr(Details),putstring("\n"), */
  364. true,!.
  365. irc_input1(_, _, _, _) :- /*
  366. write('unknown message recieved: '),
  367. writestr(MSG),
  368. tab(2),
  369. writestr(Details),putstring("\n"), */
  370. true,!.
  371. /*
  372. 0x02 02 bold
  373. 0x03 03 color
  374. 0x1f 31 underline
  375. */
  376. irc_proc([]) :- write('#0'),nl,!.
  377. irc_proc(Prefix,[Msg|Details]) :-
  378. /* write('#1:'),tab(2), write(Msg),tab(1),write(Details),putstring("\n"), */
  379. irc_input(Prefix,Msg,Details),!.
  380. /* sleep then backtrack if there is no input. obsolete. */
  381. idle([]) :- sleep(0.1), fail.
  382. idle([_|_]).
  383. irc_readiter(_, end_of_file) :- write('++idling++'),nl,sleep(0.01), !.
  384. irc_readiter(Prefix, Line) :-
  385. wordlist(AtomList, Line, []),!,
  386. irc_proc(Prefix, AtomList).
  387. /* irc_readiter(_,_) :- write('++idling++'),nl,sleep(0.01), !. */
  388. irc_readloop :-
  389. repeat,
  390. /* irc_rl2, */
  391. irc_newloop,
  392. not(app_running(true)),
  393. !.
  394. irc_rl2 :-
  395. /* sleep(0.01), */
  396. irc_recv(RawLine),!,
  397. /* idle(Line),*/
  398. putstring(RawLine),nl,!,
  399. irc_msg_prefix(Prefix, RawLine, Line),!,
  400. /* irc_msg_parse(Prefix, Cmd, Opts, Rawline, Rest */
  401. atomify(Prefix, P),
  402. irc_readiter(P, Line),!.
  403. irc_filter1(Prefix, Cmd, Opts, Line) :-
  404. irc_input1(Prefix, Cmd, Opts, Line),!.
  405. irc_filter2(Prefix, Cmd, Opts, Line) :-
  406. /* write(Prefix),nl,
  407. write(Cmd), write(' - '), write(Opts),nl, write(Line),nl,nl, */
  408. irc_input(Prefix, Cmd, Opts, Line),!.
  409. irc_filter3(Prefix, Cmd, Opts, Line) :-
  410. true.
  411. irc_newloop :-
  412. irc_recv(RawLine),!,
  413. putstring(RawLine),!,
  414. /* irc_msg_prefix(P, RawLine, L),!, */
  415. irc_msg_parse(P, Cmd, Opts, RawLine, Rest),!,
  416. atomify(P, Prefix),
  417. wordlist(AtomList, Rest, []),!,
  418. !,irc_filter1(Prefix, Cmd, Opts, AtomList),
  419. lvl2wordlist(L2List, Rest, _),
  420. !,irc_filter2(Prefix, Cmd, Opts, L2List),
  421. fail,
  422. !,irc_filter3(Prefix, Cmd, Opts, _),
  423. !.
  424. atomify([H|T], [A|B]) :- name(A,H), atomify(T,B).
  425. atomify([L|[]],[A|[]]) :- name(A,L).
  426. wordlistT([X|Y]) --> charlist(X), whitespace, wordlistT(Y).
  427. wordlistT([X]) --> whitespace, wordlistT(X).
  428. wordlistT([X]) --> charlist(X).
  429. wordlistT([X]) --> charlist(X), whitespace.
  430. wordlist([X|Y]) --> word(X), whitespace, wordlist(Y).
  431. wordlist([X]) --> whitespace, wordlist(X).
  432. wordlist([X]) --> word(X).
  433. wordlist([X]) --> word(X), whitespace.
  434. wordlist([]) --> whitespace.
  435. wordlist([]) --> re_nothing.
  436. word(W) --> charlist(X), {atom_codes(W,X)}.
  437. charlist([X|Y]) --> chr(X), charlist(Y).
  438. charlist([X]) --> chr(X).
  439. chr(X) --> [X],{X>=33, X\=58}.
  440. whitespace --> whsp, whitespace.
  441. whitespace --> whsp.
  442. whsp --> [X], {X<33}.
  443. irc_msg_parse(Prefix, Cmd, Opts) --> irc_msg_prefix(Prefix), re_command(Cmd), wordlist([Opts]), 're_:'.
  444. irc_msg_parse(Prefix, Cmd, []) --> irc_msg_prefix(Prefix), re_command(Cmd), 're_:'.
  445. irc_msg_parse(Prefix, Cmd, []) --> irc_msg_prefix(Prefix), re_command(Cmd).
  446. irc_msg_parse(Prefix, [], []) --> irc_msg_prefix(Prefix), re_nothing.
  447. irc_msg_parse([[],[],[]], [], []) --> re_nothing.
  448. re_command(C) --> re_nick(CC), {atom_codes(C,CC)}.
  449. lvl2wordlist([X|Y]) --> lvl2word(X), re_punct, lvl2wordlist(Y).
  450. lvl2wordlist([X]) --> re_punct, lvl2wordlist(X).
  451. lvl2wordlist([X]) --> lvl2word(X).
  452. lvl2wordlist([X]) --> lvl2word(X), re_punct.
  453. lvl2wordlist([]) --> re_punct.
  454. lvl2wordlist([]) --> re_nothing.
  455. lvl2word(W) --> lvl2charlist(X), {name(W,X)}.
  456. lvl2charlist([X|Y]) --> re_lvl2char(X), lvl2charlist(Y).
  457. lvl2charlist([X]) --> re_lvl2char(X).
  458. re_lvl2char(X) --> [X],{char_type(X, csym);X=45}.
  459. re_punct --> re_punct_, re_punct.
  460. re_punct --> re_punct_.
  461. re_punct_ --> [X],{X=<44}.
  462. re_punct_ --> [X],{X>=123}.
  463. re_punct_ --> [X],{X=44;X=47;X=60}.
  464. re_punct_ --> [X],{X>57,X<55}.
  465. re_punct_ --> [X],{X>90,X<95}.
  466. /*
  467. DCG used for parsing apart the packet prefixes magically.
  468. :naos.foonetic.net 001 Izbot-0001 :Welcome to the Foonetic IRC Network Izbot-0001!Izbot-0001@hostname.com
  469. */
  470. irc_msg_prefix([Nick,User,Host]) --> 're_:', re_nick(Nick), 're_!', re_user(User), 're_@', re_host(Host),re_whsp.
  471. irc_msg_prefix([Nick,User,[]]) --> re_colon, re_nick(Nick), re_expoint, re_user(User), re_whsp.
  472. irc_msg_prefix([Nick,[],[]]) --> re_colon, re_nick(Nick), re_whsp.
  473. irc_msg_prefix([[],[],[]]) --> re_nothing.
  474. re_nickchars(X) --> [X],{char_type(X, csym);X=45;X=46}.
  475. re_userchars(X) --> [X],{char_type(X, csym);X=45;X=126}.
  476. re_hostchars(X) --> [X],{char_type(X, csym);X=45;X=46}.
  477. re_nick([N|R]) --> re_nickchars(N), re_nick(R).
  478. re_nick([N]) --> re_nickchars(N).
  479. re_user([N|R]) --> re_userchars(N), re_user(R).
  480. re_user([N]) --> re_userchars(N).
  481. re_host([N|R]) --> re_hostchars(N), re_host(R).
  482. re_host([N]) --> re_hostchars(N).
  483. re_colon --> [X], {X = 58}.
  484. re_expoint --> [X], {X = 33}.
  485. re_atsign --> [X], {X = 64}.
  486. re_whsp --> [X], {X<33}.
  487. re_nothing --> [].
  488. 're_azAZ_.' --> [X],{char_type(X, csym);X=46}.
  489. 're_azAZ_-.' --> [X],{char_type(X, csym);X=46;X=45}.
  490. 're_azAZ_-' --> [X],{char_type(X, csym);X=45}.
  491. 're_:' --> [X],{X=58}.
  492. 're_!' --> [X],{X=33}.
  493. 're_@' --> [X],{X=64}.
  494. 're_+' --> [X],{X=43}.
  495. 're_%' --> [X],{X=37}.
  496. 're_&' --> [X],{X=38}.
  497. /* * * * * * * * * * * * * * * * * */
  498. /* filter chain of OR's irc_rawinput ; irc_input ; irc_englishinput */
  499. /* :daemonic.foonetic.net 353 Izbot-0001 = #ministryofsillywalks :Izbot-0001 &mo +Krisx &Liberum_Vir &Izzy */
  500. irc_powernick([Power, Nick]) --> 're_&', re_nick(N), re_nothing, {Power=admin, name(Nick,N)}.
  501. irc_powernick([Power, Nick]) --> 're_@', re_nick(N), re_nothing, {Power=op, name(Nick,N)}.
  502. irc_powernick([Power, Nick]) --> 're_%', re_nick(N), re_nothing, {Power=halfop, name(Nick,N)}.
  503. irc_powernick([Power, Nick]) --> 're_+', re_nick(N), re_nothing, {Power=voice, name(Nick,N)}.
  504. irc_powernick([Power, Nick]) --> 're_:', irc_powernick([Power, Nick]).
  505. irc_powernick([Power, Nick]) --> re_nick(N), re_nothing, {Power=user, name(Nick,N)}.
  506. irc_adduser(Chan, User, Power) :-
  507. asserta(s_userlist(Chan, User, Power)),!.
  508. irc_remuser(Chan, User) :-
  509. retractall(s_userlist(Chan, User, _)),!.
  510. irc_userlist([H|T], Chan) :-
  511. is_list(H),
  512. irc_powernick([P,N], H, _),!,
  513. irc_adduser(Chan, N, P),
  514. irc_userlist(T, Chan).
  515. irc_userlist([T], Chan) :-
  516. is_list(T),
  517. irc_powernick([P,N], T, _),!,
  518. irc_adduser(Chan, N, P).
  519. irc_userlist([], _).
  520. /* irc_msg_text([Text]) :- re_colon, re_wordlist. */
  521. re_anythingbut --> [X], {X\=45;X\=95}.
  522. re_anythingbut --> [].
  523. re_anylist --> re_anythingbut, re_anylist.
  524. re_anylist --> re_anythingbut.
  525. 're_-_-' --> re_anylist, 're_-_list', 're__-'.
  526. 're__-' --> 're___list', 're_-_list', re_anylist.
  527. 're___list' --> 're__', 're___list'.
  528. 're___list' --> 're__'.
  529. 're_-_list' --> 're_-', 're_-_list'.
  530. 're_-_list' --> 're_-'.
  531. 're__' --> [X],{X=95}.
  532. 're_-' --> [X],{X=45}.