Konversation/Scripts/Import mIRC server list/uk: Difference between revisions

From KDE UserBase Wiki
(Created page with "Скопіюйте вміст скрипту до нового текстового документа і скористайтеся дією <menuchoice>Зберегти</menuch...")
(Created page with "Переконайтеся, що роботу '''Konversation''' завершено (не просто закрито головне вікно) і віддайте команду:")
Line 14: Line 14:
Скопіюйте вміст скрипту до нового текстового документа і скористайтеся дією <menuchoice>Зберегти</menuchoice>, щоб зберегти скрипт з назвою «konversation_servers» (або будь-якою іншою назвою, не забудьте однак виправити наведені нижче команди!)
Скопіюйте вміст скрипту до нового текстового документа і скористайтеся дією <menuchoice>Зберегти</menuchoice>, щоб зберегти скрипт з назвою «konversation_servers» (або будь-якою іншою назвою, не забудьте однак виправити наведені нижче команди!)


Make sure you quit (not just close) '''Konversation''', and then run:
Переконайтеся, що роботу '''Konversation''' завершено (не просто закрито головне вікно) і віддайте команду:


:<code>    perl konversation_servers</code>
:<code>    perl konversation_servers</code>

Revision as of 08:21, 28 July 2011

Other languages:

Інформація

Цей скрипт виконує читання списку серверів mIRC з «http://www.mirc.com/servers.ini» і імпортує дані до вашого списку серверів Konversation.

  • It will NOT overwrite your existing servers, but will append the list to your existing list.
  • It doesn't integrate: If you have a freenode group now, you will have two freenode groups once you run it.
  • It sets all NEW servers to use your default profile.
  • It assumes you want to connect on the first port listed in the mIRC config. (Konversation doesn't appear to have the concept of multiple ports).

Користування

Скопіюйте вміст скрипту до нового текстового документа і скористайтеся дією Зберегти, щоб зберегти скрипт з назвою «konversation_servers» (або будь-якою іншою назвою, не забудьте однак виправити наведені нижче команди!)

Переконайтеся, що роботу Konversation завершено (не просто закрито головне вікно) і віддайте команду:

perl konversation_servers

or

perl konversation_servers /path/to/konversationrc

To run it, you will need several perl modules installed:

You can skip File::HomeDir if you include the path to your konversationrc in the command line call or if your KDEHOME environment variable is set and your konversationrc is where is should be.

Warranty

THIS SCRIPT COMES WITH NO WARRANTY AT ALL.

Support

Any questions look for Woosta on Freenode or ask your local perl guru

Licence

(c)2007 Rick Measham. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The Script

#!/usr/bin/perl

#  INFORMATION
#  ====================================================================
#  This script reads the mIRC server list from
#  'http://www.mirc.co.uk/servers.ini' and imports it into your
#  Konversation server list.
#
#  * It will NOT overwrite your existing servers, but will append the
#    list to your existing list.
#  * It doesn't integrate: If you have a freenode group now, you will
#    have two freenode groups once you run it.
#  * It sets all NEW servers to use your default profile
#  * It assumes you want to connect on the first port listed in the
#    mIRC config. (Konversation doesn't appear to have the concept of
#    multiple ports)

#  USAGE
#  ====================================================================
#  Make sure you quit (not just close) Konversation, and then run:
#
#     perl konversation_servers
#        OR
#     perl konversation_servers /path/to/konversationrc
#
#  To run it, you will need several perl modules installed:
#    * Config::Tiny
#    * LWP::Simple
#    * File::HomeDir
#
#  You can skip File::HomeDir if you include the path to your
#  konversationrc in the command line call or if your KDEHOME
#  environment variable is set and your konversationrc is where
#  is should be.
#

#  WARRANTY
#  ====================================================================
#  THIS SCRIPT COMES WITH NO WARRANTY AT ALL.
#  Any questions look for Woosta on Freenode
#

#  SUPPORT
#  ====================================================================
#  Any questions look for Woosta on Freenode or ask your local perl guru
#

#  LICENCE
#  ====================================================================
#  (c)2007 Rick Measham.  This program is free software; you can 
#  redistribute it and/or modify it under the same terms as Perl itself.
#


# Change this if it moves!
my $mirc_url = 'http://www.mirc.co.uk/servers.ini';


use warnings;
use strict;

BEGIN {

	my $konvs = `ps ax | grep konversation | grep -v grep`;
	if ($konvs =~ /konversation/){
		print "You need to quit konversation before running this script.\n";
		exit(1);
	}

	my @mod_list = ('Config::Tiny', 'File::Copy', 'LWP::Simple');

	# If there isn't a konversationrc in the ARGV, add File::HomeDir
	push(@mod_list, 'File::HomeDir')
		unless ($ARGV[0] && -r $ARGV[0])
			|| ($ENV{KDEHOME} && -r "$ENV{KDEHOME}/share/config/konversationrc");

	foreach my $mod (@mod_list){
		eval {
			(my $fn = $mod) =~ s|::|/|g;
			require $fn.'.pm';
		};
		if( $@ ){
			print "You are missing $mod. Please install this perl module and then try again.\n";
			exit(1);
		}
		import $mod;
	}
}



my $konvrc =
	($ARGV[0]) ? $ARGV[0]
	: ($ENV{KDEHOME} && -r "$ENV{KDEHOME}/share/config/konversationrc") ? "$ENV{KDEHOME}/share/config/konversationrc"
	: File::HomeDir->my_home . "/.kde/share/config/konversationrc";

print "Reading konversationrc from $konvrc\n";

if( ! -r $konvrc ){
	print "Unable to read konversationrc from $konvrc. Please include the path on the command line:\n";
	print "    /path/to/konversationrc\n";
	exit(1);
}


print "Getting server list from mirc\n";
my $servlist = get($mirc_url);
print "   done.\n";



print "Creating a backup of your current konversationrc to $konvrc.bak\n";
copy($konvrc, "$konvrc.bak");
print "   done.\n";



print "Reading INI files\n";
my $mIRC = Config::Tiny->read_string( $servlist );
my $konv = Config::Tiny->read( $konvrc );
print "   done.\n";



print "Counting existing servers\n";
my $scount = 0;
while( exists $konv->{"Server $scount"} ){
	$scount++;
}
print "   Next available server is $scount\n";



print "Counting existing server groups\n";
my $gcount = 0;
while( exists $konv->{"ServerGroup $gcount"} ){
	$gcount++;
}
print STDERR "   Next available group is $gcount\n";



print "Parsing mIRC's server list\n";
my %group;
foreach my $s ( keys %{ $mIRC->{servers} } ){

	my ($name, $server, $port, $group)
		= $mIRC->{servers}{$s}
		=~ /(.+?)SERVER:(.+?):(\d+).*?GROUP:(.+)/;

	next unless $group && $server && $port;

	$name =~ s/^$group: //;

	push(@{$group{$group}}, { name=>$name, server=>$server, port=>$port });

}
print "   done.\n";



print "Generating data for konversationrc\n";
foreach my $g ( sort keys %group ){

	$konv->{"ServerGroup $gcount"} = {
		AutoConnect         => 'false',
		AutoJoinChannels    => '',
		ChannelHistory      => '',
		ConnectCommands     => '',
		EnableNotifications => 'true',
		Expanded            => 'false',
		Identity            => 'Default Identity',
		Name                => $g,
		NotifyList          => '',
	};

	foreach my $s ( @{ $group{$g} } ){

		$konv->{"Server $scount"} = {
			Password   => '',
			Port       => $s->{port},
			SSLEnabled => 'false',
			Server     => $s->{server},
		};

		$konv->{"ServerGroup $gcount"}{ServerList} =
			($konv->{"ServerGroup $gcount"}{ServerList} || '')
			.(($konv->{"ServerGroup $gcount"}{ServerList}) ? ',' : '')
			."Server $scount";

		$scount++;
	}

	$gcount++;
}
$gcount--; $scount--;
print "   done. There are now $gcount groups and $scount servers.\n";



print "Writing konversationrc\n";
$konv->write($konvrc);
print "   done.\n";



print "Completed. It is now safe to start konversation.\n";