BeBot - An Anarchy Online and Age Of Conan chat automaton
Development => Module Requests => Topic started by: IKShadow on November 16, 2008, 07:56:39 am
-
I made a custom module that logs into database all log on/off messages so I can query members playtimes.
/*
This gets called if a buddy logs on/off if you previously registered the event 'buddy'
*/
function buddy($name, $msg) .....
There is weird thing that I have multiple log on messages ( status=1 ) with missing log off ones ( status = 0 )
Example:id nickname status timestamp from_unixtime(timestamp)
1 Ikshadow 1 1223476398 8.10.2008 16:33
13 Ikshadow 0 1223476414 8.10.2008 16:33
36 Ikshadow 1 1223479520 8.10.2008 17:25
41 Ikshadow 1 1.223479879 8.10.2008 17:31
72 Ikshadow 1 1223481387 8.10.2008 17:56
85 Ikshadow 1 1223481481 8.10.2008 17:58
100 Ikshadow 0 1223482833 8.10.2008 18:20
107 Ikshadow 1 1223484069 8.10.2008 18:41
123 Ikshadow 1 1223484170 8.10.2008 18:42
138 Ikshadow 1 1223484374 8.10.2008 18:46
157 Ikshadow 1 1223484928 8.10.2008 18:55
183 Ikshadow 1 1223485323 8.10.2008 19:02
205 Ikshadow 1 1223485472 8.10.2008 19:04
228 Ikshadow 1 1223485733 8.10.2008 19:08
267 Ikshadow 1 1223486327 8.10.2008 19:18
381 Ikshadow 1 1223489290 8.10.2008 20:08
445 Ikshadow 0 1223.490.463 8.10.2008 20:27
531 Ikshadow 1 1223493594 8.10.2008 21:19
568 Ikshadow 0 1223494924 8.10.2008 21:42
I thought BOT do whois on each member in user list every xxx seconds and show notify message only when previous status is changed.
For some wierd reason I have all that data in database however I never notice in guild chat that BOT would spam twice:
[GROUP] [MSG] [~Guild] Echo: "Ikshadow" (Lvl 80Ranger)Logged On :: [link]Details[/link]
[GROUP] [MSG] [~Guild] Echo: "Ikshadow" (Lvl 80Ranger)Logged On :: [link]Details[/link]
etc..
Bot log file:[2008-11-16 02:40:31] [BUDDY] [LOG] Ikshadow changed status [1] (OWNER)
[2008-11-16 02:40:36] [BUDDY] [LOG] Ikshadow changed status [6] (OWNER)
[2008-11-16 02:40:37] [GROUP] [MSG] [~Guild] Echo: "Ikshadow" (Lvl 80Ranger)Logged On :: [link]Details[/link] :: Have no fear IKShadow is here :)
[2008-11-16 02:40:37] [PGRP] [MSG] [Echo] Echo: "Ikshadow" (Lvl 80Ranger)Logged On :: [link]Details[/link] :: Have no fear IKShadow is here :)
[2008-11-16 02:40:46] [TELL] [OUT] -> Ikshadow: News last updated November 15th, 2008 16:25:: [link]click to view[/link]
Now the problem is that I may get "member 1 logged in 7:00 am" and then "member 1 logged in 23:00 am" the member logged off is missing.
Anyone know what could be the problem ?
-
I don't know which buddy events AoC creates when a player logs in. Depending on the way the events happen and are parsed into the table there may happen several events.
Best way would be to add debug-output to the buddy() function.
On a similar note you should make sure that you don't start parsing too soon after startup as the buddy events on bot startup are fairly extensive.
-
It's normal for the buddy logon event to fire multiple times while a player is online.
This is due to changing values like which playfield they are in.
-
Yea but the problem is that sometimes it missed log off events aka status 0.
I dont mind multiple online but if off line are missing then its hard to calculate exact time .. now i just skip all status online that are not close with offline one ( and there is lots and lots of them ).
Any chance I could run something in crontab that would recheck all those with status online and give them status offline if they are disconnected.
-
yes u can
u can check the status of any 1 on the buddy list at any time
with somit like
if($this -> bot -> core("chat") -> buddy_exists($name))
$status = $this -> bot -> core("chat") -> buddy_online($name)
$status will be (bool) TRUE or FALSE
-
yes u can
u can check the status of any 1 on the buddy list at any time
with somit like
if($this -> bot -> core("chat") -> buddy_exists($name))
$status = $this -> bot -> core("chat") -> buddy_online($name)
$status will be (bool) TRUE or FALSE
Thanks
Any chance you can tell me how to put that in cron tab.
I would modify my modul so every 5 minutes I would check for member status and update my log sql table.
p.s. It would be better if I could only re-check those that are marked online so BOT does not get to busy.
-
1st you need this at top in __construct
$this -> register_event("cron", "5min");
then
function cron()
{
$online = $this -> bot -> db -> select("SELECT nickname FROM #___online WHERE status_gc = 1");
if(!empty($online))
{
foreach($online as $user)
{
if($this -> bot -> core("chat") -> buddy_exists($name))
{
if(!$this -> bot -> core("chat") -> buddy_online($name))
{
// do wateva to make user as offline
}
}
}
}
}
}
-
thanks for quick response.
-
I made a custom module that logs into database all log on/off messages so I can query members playtimes.
/*
This gets called if a buddy logs on/off if you previously registered the event 'buddy'
*/
function buddy($name, $msg) .....
There is weird thing that I have multiple log on messages ( status=1 ) with missing log off ones ( status = 0 )
Example:id nickname status timestamp from_unixtime(timestamp)
1 Ikshadow 1 1223476398 8.10.2008 16:33
13 Ikshadow 0 1223476414 8.10.2008 16:33
36 Ikshadow 1 1223479520 8.10.2008 17:25
41 Ikshadow 1 1.223479879 8.10.2008 17:31
72 Ikshadow 1 1223481387 8.10.2008 17:56
85 Ikshadow 1 1223481481 8.10.2008 17:58
100 Ikshadow 0 1223482833 8.10.2008 18:20
107 Ikshadow 1 1223484069 8.10.2008 18:41
123 Ikshadow 1 1223484170 8.10.2008 18:42
138 Ikshadow 1 1223484374 8.10.2008 18:46
157 Ikshadow 1 1223484928 8.10.2008 18:55
183 Ikshadow 1 1223485323 8.10.2008 19:02
205 Ikshadow 1 1223485472 8.10.2008 19:04
228 Ikshadow 1 1223485733 8.10.2008 19:08
267 Ikshadow 1 1223486327 8.10.2008 19:18
381 Ikshadow 1 1223489290 8.10.2008 20:08
445 Ikshadow 0 1223.490.463 8.10.2008 20:27
531 Ikshadow 1 1223493594 8.10.2008 21:19
568 Ikshadow 0 1223494924 8.10.2008 21:42
I thought BOT do whois on each member in user list every xxx seconds and show notify message only when previous status is changed.
For some wierd reason I have all that data in database however I never notice in guild chat that BOT would spam twice:
[GROUP] [MSG] [~Guild] Echo: "Ikshadow" (Lvl 80Ranger)Logged On :: [link]Details[/link]
[GROUP] [MSG] [~Guild] Echo: "Ikshadow" (Lvl 80Ranger)Logged On :: [link]Details[/link]
etc..
Bot log file:[2008-11-16 02:40:31] [BUDDY] [LOG] Ikshadow changed status [1] (OWNER)
[2008-11-16 02:40:36] [BUDDY] [LOG] Ikshadow changed status [6] (OWNER)
[2008-11-16 02:40:37] [GROUP] [MSG] [~Guild] Echo: "Ikshadow" (Lvl 80Ranger)Logged On :: [link]Details[/link] :: Have no fear IKShadow is here :)
[2008-11-16 02:40:37] [PGRP] [MSG] [Echo] Echo: "Ikshadow" (Lvl 80Ranger)Logged On :: [link]Details[/link] :: Have no fear IKShadow is here :)
[2008-11-16 02:40:46] [TELL] [OUT] -> Ikshadow: News last updated November 15th, 2008 16:25:: [link]click to view[/link]
Now the problem is that I may get "member 1 logged in 7:00 am" and then "member 1 logged in 23:00 am" the member logged off is missing.
Anyone know what could be the problem ?
Sound interesting... mind sharing the code?
-
Nothing to share really .. its just store info in DB
So far I only do manual queries to check play times ( mostly to catch the spies )
<?php
$this_buddy_status_logger = new buddy_status_logger($bot);
class buddy_status_logger extends BaseActiveModule
{
function __construct (&$bot)
{
//Initialize the base module
parent::__construct(&$bot, get_class($this));
$this->register_event('buddy');
$this -> bot -> db -> query("CREATE TABLE IF NOT EXISTS " . $this -> bot -> db -> define_tablename("buddy_status_log", "true") . "
(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, nickname VARCHAR(25), status TINYINT(1), timestamp INT)");
}
/*
Unified message handler
$source: The originating player
$msg: The actual message, including command prefix and all
$type: The channel the message arrived from. This can be either "tell", "pgmsg" or "gc"
*/
function command_handler($source, $msg, $origin)
{
//ALWAYS reset the error handler before parsing the commands to prevent stale errors from giving false reports
$this->error->reset();
}
/*
This gets called if a buddy logs on/off if you previously registered the event 'buddy'
*/
function buddy($name, $msg)
{
$sql = "INSERT INTO hyborian_buddy_status_log (nickname, status, timestamp) ";
$sql .= "VALUES ('$name', '$msg', UNIX_TIMESTAMP(NOW()))";
$result = $this -> bot -> db -> query($sql);
if ($result===false)
{
$this->error->set("An unknown error occurred inserting buddy status log.");
return ($this->error);
}
}
}
?>