Jump to content

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

From KDE Wiki Sandbox
Annew (talk | contribs)
No edit summary
Annew (talk | contribs)
Marked this version for translation
Line 2: Line 2:
<translate>
<translate>


== Information ==
== Information == <!--T:1-->


<!--T:2-->
This script reads the mIRC server list from 'http://www.mirc.com/servers.ini' and imports it into your '''Konversation''' server list.
This script reads the mIRC server list from 'http://www.mirc.com/servers.ini' and imports it into your '''Konversation''' server list.


<!--T:3-->
* It will NOT overwrite your existing servers, but will append the list to your existing 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 doesn't integrate: If you have a freenode group now, you will have two freenode groups once you run it.
Line 11: Line 13:
* 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).
* 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 ==
== Usage == <!--T:4-->


<!--T:5-->
Copy the script below into a new text document and <menuchoice>Save</menuchoice> it as 'konversation_servers' (or really any name you care, just change the following to suit!)
Copy the script below into a new text document and <menuchoice>Save</menuchoice> it as 'konversation_servers' (or really any name you care, just change the following to suit!)


<!--T:6-->
Make sure you quit (not just close) '''Konversation''', and then run:
Make sure you quit (not just close) '''Konversation''', and then run:


<!--T:7-->
:<code>    perl konversation_servers</code>
:<code>    perl konversation_servers</code>
or
or
:<code>    perl konversation_servers /path/to/konversationrc</code>
:<code>    perl konversation_servers /path/to/konversationrc</code>


<!--T:8-->
To run it, you will need several perl modules installed:
To run it, you will need several perl modules installed:


<!--T:9-->
* [http://search.cpan.org/search?query=Config%3A%3ATiny&mode=module Config::Tiny]
* [http://search.cpan.org/search?query=Config%3A%3ATiny&mode=module Config::Tiny]
* [http://search.cpan.org/search?query=LWP%3A%3ASimple&mode=module LWP::Simple]
* [http://search.cpan.org/search?query=LWP%3A%3ASimple&mode=module LWP::Simple]
* [http://search.cpan.org/search?query=File%3A%3AHomeDir&mode=module File::HomeDir]
* [http://search.cpan.org/search?query=File%3A%3AHomeDir&mode=module File::HomeDir]


<!--T:10-->
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.
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 ==
== Warranty == <!--T:11-->


<!--T:12-->
THIS SCRIPT COMES WITH NO WARRANTY AT ALL.
THIS SCRIPT COMES WITH NO WARRANTY AT ALL.


== Support ==
== Support == <!--T:13-->


<!--T:14-->
Any questions look for Woosta on Freenode or ask your local perl guru
Any questions look for Woosta on Freenode or ask your local perl guru


== Licence ==
== Licence == <!--T:15-->


<!--T:16-->
(c)2007 Rick Measham.  This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
(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 ==
== The Script == <!--T:17-->


<!--T:18-->
{{Input|<syntaxhighlight lang="perl">
{{Input|<syntaxhighlight lang="perl">
#!/usr/bin/perl
#!/usr/bin/perl


<!--T:19-->
#  INFORMATION
#  INFORMATION
#  ====================================================================
#  ====================================================================
Line 61: Line 74:
#    multiple ports)
#    multiple ports)


<!--T:20-->
#  USAGE
#  USAGE
#  ====================================================================
#  ====================================================================
Line 80: Line 94:
#
#


<!--T:21-->
#  WARRANTY
#  WARRANTY
#  ====================================================================
#  ====================================================================
Line 86: Line 101:
#
#


<!--T:22-->
#  SUPPORT
#  SUPPORT
#  ====================================================================
#  ====================================================================
Line 91: Line 107:
#
#


<!--T:23-->
#  LICENCE
#  LICENCE
#  ====================================================================
#  ====================================================================
Line 98: Line 115:




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




<!--T:25-->
use warnings;
use warnings;
use strict;
use strict;


<!--T:26-->
BEGIN {
BEGIN {


my $konvs = `ps ax | grep konversation | grep -v grep`;
<!--T:27-->
my $konvs = `ps ax | grep konversation | grep -v grep`;
if ($konvs =~ /konversation/){
if ($konvs =~ /konversation/){
print "You need to quit konversation before running this script.\n";
print "You need to quit konversation before running this script.\n";
Line 113: Line 134:
}
}


my @mod_list = ('Config::Tiny', 'File::Copy', 'LWP::Simple');
<!--T:28-->
my @mod_list = ('Config::Tiny', 'File::Copy', 'LWP::Simple');


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


foreach my $mod (@mod_list){
<!--T:30-->
foreach my $mod (@mod_list){
eval {
eval {
(my $fn = $mod) =~ s|::|/|g;
(my $fn = $mod) =~ s|::|/|g;
Line 135: Line 159:




<!--T:31-->
my $konvrc =
my $konvrc =
($ARGV[0]) ? $ARGV[0]
($ARGV[0]) ? $ARGV[0]
Line 140: Line 165:
: File::HomeDir->my_home . "/.kde/share/config/konversationrc";
: File::HomeDir->my_home . "/.kde/share/config/konversationrc";


<!--T:32-->
print "Reading konversationrc from $konvrc\n";
print "Reading konversationrc from $konvrc\n";


<!--T:33-->
if( ! -r $konvrc ){
if( ! -r $konvrc ){
print "Unable to read konversationrc from $konvrc. Please include the path on the command line:\n";
print "Unable to read konversationrc from $konvrc. Please include the path on the command line:\n";
Line 149: Line 176:




<!--T:34-->
print "Getting server list from mirc\n";
print "Getting server list from mirc\n";
my $servlist = get($mirc_url);
my $servlist = get($mirc_url);
Line 155: Line 183:




<!--T:35-->
print "Creating a backup of your current konversationrc to $konvrc.bak\n";
print "Creating a backup of your current konversationrc to $konvrc.bak\n";
copy($konvrc, "$konvrc.bak");
copy($konvrc, "$konvrc.bak");
Line 161: Line 190:




<!--T:36-->
print "Reading INI files\n";
print "Reading INI files\n";
my $mIRC = Config::Tiny->read_string( $servlist );
my $mIRC = Config::Tiny->read_string( $servlist );
Line 168: Line 198:




<!--T:37-->
print "Counting existing servers\n";
print "Counting existing servers\n";
my $scount = 0;
my $scount = 0;
Line 177: Line 208:




<!--T:38-->
print "Counting existing server groups\n";
print "Counting existing server groups\n";
my $gcount = 0;
my $gcount = 0;
Line 186: Line 218:




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


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


next unless $group && $server && $port;
<!--T:41-->
next unless $group && $server && $port;


$name =~ s/^$group: //;
<!--T:42-->
$name =~ s/^$group: //;


push(@{$group{$group}}, { name=>$name, server=>$server, port=>$port });
<!--T:43-->
push(@{$group{$group}}, { name=>$name, server=>$server, port=>$port });


<!--T:44-->
}
}
print "  done.\n";
print "  done.\n";
Line 205: Line 243:




<!--T:45-->
print "Generating data for konversationrc\n";
print "Generating data for konversationrc\n";
foreach my $g ( sort keys %group ){
foreach my $g ( sort keys %group ){


$konv->{"ServerGroup $gcount"} = {
<!--T:46-->
$konv->{"ServerGroup $gcount"} = {
AutoConnect        => 'false',
AutoConnect        => 'false',
AutoJoinChannels    => '',
AutoJoinChannels    => '',
Line 220: Line 260:
};
};


foreach my $s ( @{ $group{$g} } ){
<!--T:47-->
foreach my $s ( @{ $group{$g} } ){


$konv->{"Server $scount"} = {
<!--T:48-->
$konv->{"Server $scount"} = {
Password  => '',
Password  => '',
Port      => $s->{port},
Port      => $s->{port},
Line 229: Line 271:
};
};


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


$scount++;
<!--T:50-->
$scount++;
}
}


$gcount++;
<!--T:51-->
$gcount++;
}
}
$gcount--; $scount--;
$gcount--; $scount--;
Line 244: Line 289:




<!--T:52-->
print "Writing konversationrc\n";
print "Writing konversationrc\n";
$konv->write($konvrc);
$konv->write($konvrc);
Line 250: Line 296:




<!--T:53-->
print "Completed. It is now safe to start konversation.\n";
print "Completed. It is now safe to start konversation.\n";
</syntaxhighlight>}}
</syntaxhighlight>}}


<!--T:54-->
[[Category:Internet]]
[[Category:Internet]]
[[Category:Advanced Users]]
[[Category:Advanced Users]]
</translate>
</translate>

Revision as of 06:17, 28 July 2011

Information

This script reads the mIRC server list from 'http://www.mirc.com/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

Copy the script below into a new text document and Save it as 'konversation_servers' (or really any name you care, just change the following to suit!)

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:

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";