koreTwitter - Twitter support for OpenKore (12/30/2008 #2)

Other plugins for extending OpenKore's functionality. This forum is only for posting new plugins and commenting on existing plugins. For support, use the Support forum.

Moderator: Moderators

Message
Author
sli
Perl Monk
Perl Monk
Posts: 810
Joined: 04 Apr 2008, 17:26
Noob?: No

koreTwitter - Twitter support for OpenKore (12/30/2008 #2)

#1 Post by sli »

Update 2: New features! I added four config options: koreTwitter_owner, koreTwitter_ignore, koreTwitter_direct, and koreTwitter_reply. The first is required for the third and fourth to become available. I also added message domains (similar to OpenKore's domains).

Here are all the domains:
  • msg - Private message received
  • base - Base level gained
  • job - Job level gained
  • died - Bot has died
  • pvp - Bot has entered a PVP area
  • gm - A GM alert
  • ingame - Your bot is now in game
  • item - Your bot has found an item listed in koreTwitter_items
Now allow me to explain koreTwitter_ignore. This option allows you to set a list of domains that will not send a tweet. Simple.

As for koreTwitter_direct and koreTwitter_reply, they control how tweets are sent. koreTwitter_direct takes priority, so you can't specify the same domain twice (to prevent retweets). These options contain a list of message domains that will be sent in a certain manner, specifically direct messages or @reply-style, respectively. Any domain not in this list will default to a normal tweet, unless of course it's in the ignore list. Below is a sample config that will direct message GM alerts, @reply deaths, base levels, and job levels, ignore the ingame domain, and use regular tweets for everything else.

Code: Select all

koreTwitter 1
koreTwitter_username ausername
koreTwitter_password somepass
koreTwitter_items Clip [1]
koreTwitter_owner sli
koreTwitter_direct gm
koreTwitter_reply died, base, job
koreTwitter_ignore ingame
Update: Added character names to PM tweets so you can run multiple bots on one Twitter account without confusion.

This plugin sends status updates to Twitter must like koreSnarl/Growl displays notifications. It uses the same events. Handy for keeping track of your bot while you're out of the house. One of these days I'll add support for receiving commands via Twitter. If you use koreSnarl/Growl, I would suggest giving this a try. It maintains a sort of message persistence that you don't get with koreSnarl/Growl in that all information it displays remains accessible on Twitter, unlike koreSnarl/Growl where the information disappears after five seconds or so. If you're botting overnight, you'll miss a lot of information.

To using this plugin, you'll need to install Net::Twitter, which also requires JSON. Cpan handles it no problem (cpan> install Net::Twitter). h4rry84 has checked and Net::Twitter can be installed from PPM if you're using ActiveState.

Sample config:

Code: Select all

koreTwitter 1
koreTwitter_username twitterusername
koreTwitter_password twitterpassword
koreTwitter_items Soldier Skeleton Card, Verit Card
And here's the plugin:

Code: Select all

#########################################
# koreTwitter.pl: Written by sli        #
#                                       #
# This plugin lets your bot post status #
# status updates to a Twitter account.  #
#                                       #
#########################################

package koreTwitter;

use Plugins;
use Globals qw($char %config %timeout);
use Settings;
use FindBin qw($RealBin);

use Net::Twitter;

Plugins::register('koreTwitter','Allows your bot to post status updates to Twitter.', \&onUnload);
my $hooks = Plugins::addHooks(
	['start3', \&onLoad, undef],
	['packet_privMsg', \&onPrivMsg, undef],
	['base_level', \&onLevelUp, undef],
	['self_died', \&onDeath, undef],
	['job_level', \&onJLevelUp, undef],
	['pvp_mode', \&onPvpMode, undef],
	['avoidGM_near', \&onGm, undef],
	['avoidGM_talk', \&onGm, undef],
	['in_game', \&onInGame, undef],
	['item_gathered', \&onItemFound, undef],
	['Network::Receive::map_changed', \&onMapChange, undef]
);

my $cmd = Commands::register(
	["tweet", "Posts a status update to Twitter.", \&cmdTweet],
);

our $dead = 0;
our $twit;

sub cmdTweet {
	my @args = @_;
	tweet($args[1]);
}

sub onLoad {
	if (defined $config{koreTwitter_username} && defined $config{koreTwitter_password}) {
		$twit = Net::Twitter->new(username=>$config{koreTwitter_username}, password=>$config{koreTwitter_password});
	}
}

sub onPrivMsg {
	my @args = @_;
	tweet("From $args[1]{'privMsgUser'} : $args[1]{privMsg}", "msg");
}

sub onLevelUp {
	@args = shift;
	tweet("$char->{name} has gained a level!", "base") unless ($args{name} ne $char->{name});
}

sub onJLevelUp {
	@args = shift;
	tweet("$char->{name} has gained a job level!", "job") unless ($args{name} ne $char->{name});
}

sub onDeath {
	tweet("$char->{name} has died!", "died") unless ($dead);
	$dead = 1;
}

sub onPvpMode {
	tweet("WARNING: $char->{name} has entered a PVP area!", "pvp");
}

sub onGm {
	my $ucname = uc($char->{name}) unless $ucname;
	tweet("WARNING: GM IS NEAR $ucname!", "gm");
}

sub onInGame {
	tweet("$char->{name} is now in game.", "ingame");
}

sub onItemFound {
	my @args = @_;
	if ($config{koreTwitter_items} =~ /$args[1]{item}/i) {
		tweet("$char->{name} has found a $args[1]{item}!", "item");
	}
}

sub onMapChange {
	# Prevents multiple notifications on death.
	$dead = 0;
}

sub tweet {
	my ($msg, $domain) = @_;
	if ($config{koreTwitter} == 1) {
		if (defined $config{koreTwitter_owner})
			if ($config{koreTwitter_direct} =~ /$domain/i) {
				$twit->update("d $config{koreTwitter_owner} $msg");
			} elsif ($config{koreTwitter_reply} =~/$domain/i) {
				$twit->update("@" . "$config{koreTwitter_owner}" . " $msg");
			} else {
				$twit->update($msg);
			}
		} else {
			$twit->update($msg);
		}
	}
}

sub onUnload {
	Plugins::delHooks($hooks);
	undef $ucname;
}

1;
cs : ee : realist

h4rry84
Moderators
Moderators
Posts: 234
Joined: 04 Apr 2008, 09:30
Noob?: Yes
Location: My House
Contact:

Re: koreTwitter - Twitter support for OpenKore (12/11/2008)

#2 Post by h4rry84 »

Just search Twitter in Activestate PPM, and it will get right :) (Net-Twitter)

sli
Perl Monk
Perl Monk
Posts: 810
Joined: 04 Apr 2008, 17:26
Noob?: No

Re: koreTwitter - Twitter support for OpenKore (12/11/2008)

#3 Post by sli »

Alright, I thought so. Thanks for checking for me. Like I said, I use Strawberry Perl and CPAN, so I have no idea what's available on PPM.
cs : ee : realist

sli
Perl Monk
Perl Monk
Posts: 810
Joined: 04 Apr 2008, 17:26
Noob?: No

Re: koreTwitter - Twitter support for OpenKore (12/30/2008)

#4 Post by sli »

Bump for small but useful update.
cs : ee : realist

sli
Perl Monk
Perl Monk
Posts: 810
Joined: 04 Apr 2008, 17:26
Noob?: No

Re: koreTwitter - Twitter support for OpenKore (12/30/2008)

#5 Post by sli »

Another bump for a BIG update! Except koreNotify updates as well.
cs : ee : realist

mranderson
Noob
Noob
Posts: 1
Joined: 03 Aug 2009, 20:07
Noob?: Yes

Re: koreTwitter - Twitter support for OpenKore (12/30/2008 #2)

#6 Post by mranderson »

Hi, I'm Trying to install this plugin but have never used plugins before can you help?

Here is what I have done:
1-installed ActiveState on computer.
2-Searched Net::Twitter and istalled the package to c:/Perl which istalled 40 other package as well.
3-copy pasted the " koreTwitter.pl: Written by sli " to openkore plugins folder
4-added the lines" koreTwitter 1 koreTwitter_username twitterusername koreTwitter_password twitterpassword'
in my bot config with twitter username password.
5-launched openkore and then error could not find Net in src/.....

So I guessed I installed the package wrong can someone give me a more detailed explanation to get the package to openkore.

Thank you in advance for your help.

User avatar
twist3d
Testers Team
Testers Team
Posts: 94
Joined: 09 Sep 2009, 04:34
Noob?: No
Location: USA

Re: koreTwitter - Twitter support for OpenKore (12/30/2008 #2)

#7 Post by twist3d »

There is a problem with your code, around like 100 its missing a { on the "if (defined $config{koreTwitter_owner})" line

so it should be:

Code: Select all

#########################################
# koreTwitter.pl: Written by sli        #
#                                       #
# This plugin lets your bot post status #
# status updates to a Twitter account.  #
#                                       #
#########################################

package koreTwitter;

use Plugins;
use Globals qw($char %config %timeout);
use Settings;
use FindBin qw($RealBin);

use Net::Twitter;

Plugins::register('koreTwitter','Allows your bot to post status updates to Twitter.', \&onUnload);
my $hooks = Plugins::addHooks(
   ['start3', \&onLoad, undef],
   ['packet_privMsg', \&onPrivMsg, undef],
   ['base_level', \&onLevelUp, undef],
   ['self_died', \&onDeath, undef],
   ['job_level', \&onJLevelUp, undef],
   ['pvp_mode', \&onPvpMode, undef],
   ['avoidGM_near', \&onGm, undef],
   ['avoidGM_talk', \&onGm, undef],
   ['in_game', \&onInGame, undef],
   ['item_gathered', \&onItemFound, undef],
   ['Network::Receive::map_changed', \&onMapChange, undef]
);

my $cmd = Commands::register(
   ["tweet", "Posts a status update to Twitter.", \&cmdTweet],
);

our $dead = 0;
our $twit;

sub cmdTweet {
   my @args = @_;
   tweet($args[1]);
}

sub onLoad {
   if (defined $config{koreTwitter_username} && defined $config{koreTwitter_password}) {
      $twit = Net::Twitter->new(username=>$config{koreTwitter_username}, password=>$config{koreTwitter_password});
   }
}

sub onPrivMsg {
   my @args = @_;
   tweet("From $args[1]{'privMsgUser'} : $args[1]{privMsg}", "msg");
}

sub onLevelUp {
   @args = shift;
   tweet("$char->{name} has gained a level!", "base") unless ($args{name} ne $char->{name});
}

sub onJLevelUp {
   @args = shift;
   tweet("$char->{name} has gained a job level!", "job") unless ($args{name} ne $char->{name});
}

sub onDeath {
   tweet("$char->{name} has died!", "died") unless ($dead);
   $dead = 1;
}

sub onPvpMode {
   tweet("WARNING: $char->{name} has entered a PVP area!", "pvp");
}

sub onGm {
   my $ucname = uc($char->{name}) unless $ucname;
   tweet("WARNING: GM IS NEAR $ucname!", "gm");
}

sub onInGame {
   tweet("$char->{name} is now in game.", "ingame");
}

sub onItemFound {
   my @args = @_;
   if ($config{koreTwitter_items} =~ /$args[1]{item}/i) {
      tweet("$char->{name} has found a $args[1]{item}!", "item");
   }
}

sub onMapChange {
   # Prevents multiple notifications on death.
   $dead = 0;
}

sub tweet {
   my ($msg, $domain) = @_;
   if ($config{koreTwitter} == 1) {
      if (defined $config{koreTwitter_owner})[color=#FF0000]{[/color]
         if ($config{koreTwitter_direct} =~ /$domain/i) {
            $twit->update("d $config{koreTwitter_owner} $msg");
         } elsif ($config{koreTwitter_reply} =~/$domain/i) {
            $twit->update("@" . "$config{koreTwitter_owner}" . " $msg");
         } else {
            $twit->update($msg);
         }
      } else {
         $twit->update($msg);
      }
   }
}

sub onUnload {
   Plugins::delHooks($hooks);
   undef $ucname;
}

1;
Member since 09/09/09, botter since its first creation days. Thanks Kura for the original Kore.

Montsec
Noob
Noob
Posts: 3
Joined: 30 Oct 2009, 10:40
Noob?: No

Re: koreTwitter - Twitter support for OpenKore (12/30/2008 #2)

#8 Post by Montsec »

How can we extend the plugin? I am a noob at this, but I would like to add alerts for warnings about Teleporting to avoid certain monsters.

I added this in the list of hooks-

Code: Select all

   ['teleport_sent', \&onTeleport, undef],
and then put this in-

Code: Select all

sub onTeleport {
  tweet("$char->{name} teleported to avoid a monster!", "teleport");
}
Edit: Fixed a dumb mistake in the sub

Scarya
Moderators
Moderators
Posts: 136
Joined: 26 May 2008, 12:25
Noob?: No

Re: koreTwitter - Twitter support for OpenKore (12/30/2008 #2)

#9 Post by Scarya »

Code: Select all

   ['teleport_sent', \&onTeleport, undef],
This will send always send a tweet if you're teleporting even if it's because routing.
So with route_teleport you will be spamed hard.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs and the universe trying to produce bigger and better idiots.
So far, the universe is winning.

Richard Cook

Wiki

Montsec
Noob
Noob
Posts: 3
Joined: 30 Oct 2009, 10:40
Noob?: No

Re: koreTwitter - Twitter support for OpenKore (12/30/2008 #2)

#10 Post by Montsec »

Scarya wrote:

Code: Select all

   ['teleport_sent', \&onTeleport, undef],
This will send always send a tweet if you're teleporting even if it's because routing.
So with route_teleport you will be spamed hard.
well, i am really new on this, if you know how to get the hook for teleporting only for a monster, or how to extract out the hooks, I would appreciate any tips, thx.
i got the hook info from the other thread...

Post Reply