dellog.pl 2.35 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# Copyright (c) 2009 by Nils Görs <weechatter@arcor.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
16
# v0.2: /mute function added (needs weechat v0.3.2 and higher!)
17 18 19 20 21 22 23 24
# v0.1: first release
#
# This script DELETES the log file for the current buffer
#
# You are using this script at your risk.
#

use strict;
25
my $version = "0.2";
26 27 28 29 30 31 32 33 34
my $description = "delete log file";
my $program_name = "dellog";

# first function called by a WeeChat-script
weechat::register($program_name, "Nils Görs <weechatter\@arcor.de>", $version,
                  "GPL3", $description, "", "");

weechat::hook_command($program_name, $description,
	"[delete]", 
35
	"delete: delete log file from current buffer\n",
36 37 38 39 40 41 42 43
	"delete","getargs", "");
return weechat::WEECHAT_RC_OK;


sub getargs{
  my ($buffer, $args) = ($_[1], $_[2]);				# get argument 
  $args = lc($args);						# switch argument to lower-case
    if ($args eq "delete"){
44
	get_logfile_name();
45 46 47 48 49 50
    }
return weechat::WEECHAT_RC_OK;
}


sub get_logfile_name{						# get name of current name of log-file
51

52 53 54 55
  my $buffer = weechat::current_buffer;				# get current buffer name
    my $linfolist = weechat::infolist_get("logger_buffer", "", "");

    while(weechat::infolist_next($linfolist)){
56
      my $bpointer = weechat::infolist_pointer($linfolist, "buffer");
57
        if($bpointer eq $buffer){
58 59 60 61 62 63 64
	  my $logfilename = weechat::infolist_string($linfolist, "log_filename");
	  my $log_enabled = weechat::infolist_integer($linfolist, "log_enabled");
	  my $log_level = weechat::infolist_integer($linfolist, "log_level");
	  weechat::command($buffer, "/mute logger disable");	# disable file logging
	  unlink($logfilename);					# DELETE Log-file
	  weechat::command($buffer,"/mute logger set " . $log_level);# start file logging again
	  last;
65 66 67 68
	}
    }
      weechat::infolist_free($linfolist);
}