Sunday, April 25, 2010

Twitter Integration - Badges and Customization

As previously posted on this blog, HeroStats contains some basic Twitter integration features. Since that posting, some new features have been added. Most notably, you can choose to tweet when your character earns a badge. This is present in HeroStats 4.9.1.7 and above (including the upcoming 5.x stable builds).

You'll first need to set up Twitter integration as described in the previous blog post. You'll notice that the configuration screen looks a bit different than the screenshots in that post, though.


If you un-check the first checkbox, HeroStats won't send a tweet when you complete the Twitter setup. This is handy if you're setting this up more than once, and don't want to spam a bunch of setup tweets.

The second checkbox is for level-up tweets. In addition to the ability to turn it on or off completely with the checkbox, you can now choose a lower limit on the levels to tweet about. The default configuration is 10, so HeroStats won't tweet when your characters reach levels 2-9, but will tweet for every level 10 or higher. This helps to minimize the Twitter spam since those lowbie levels often go by very quickly.

The third checkbox is the new badge tweet functionality. It's turned off by default. If you check this box, then HeroStats will tweet when you earn a new badge. However, it will only check for new badges as often as the number of seconds listed (300 by default). This is again a measure to prevent large numbers of tweets. Completing a task force, picking up zone explore badges, or even just creating a new character often results in obtaining several badges all at once. Rather than posting a separate tweet for each one, HeroStats will tweet just once every five minutes, with a summary something like this:

Flame of Ebony (50 Magic Blaster on Victory) just earned City Official and 1 other badge in City of Heroes! #coh

The first badge you earned will be named, and then a count of how many other badges you've gotten since the last tweet.

Here's a sample of how my configuration looks once I've done the Twitter setup:


Finally, it is possible to customize the text of your tweets. I haven't yet provided a user interface for this, but it is possible as long as you aren't scared by a little XML. Make sure you've completed the Twitter setup steps, then shut down HeroStats. Go to your HeroStats directory and open the file called "HeroStatsConfig.xml" in a text editor. (This is probably not the default program - that's usually Internet Explorer - so you can't just double-click it.)

Inside that file you'll find two lines that look like this:

<twitterlevelupmsg>$name ($origin $archetype on $server) just reached level $level in $game! #coh</twitterlevelupmsg>

<twitterbadgemsg>$name ($origin $archetype on $server) just earned $badges in $game! #coh</twitterbadgemsg>

The level-up message is the bit between <twitterlevelupmsg> and </twitterlevelupmsg>, and the badge message is the bit between <twitterbadgemsg> and </twitterbadgemsg>.

There are several variables in these messages that you can use:

$level: This is the current level of your character. Note that the level-up tweet happens after you gain a level, so in that case this is your new level.

$name, $origin and $archetype: These work just like in the game client, showing the current character's name/origin/archetype.

$server: The server that your character is on.

$game: Either "City of Heroes" or "City of Villains" based on your character's archetype. (I'm not sure yet how I'm going to deal with this after Going Rogue allows switching sides...we'll see.)

$badges: The badges you've earned since the last badge tweet. This won't include every badge name, but rather the first badge you earned in that time plus a count of additional badges. Examples: "Whitecap" (for just one badge) or "Whitecap and 1 other badge" (for 2 badges) or "Whitecap and 2 other badges" (for 3 badges).

You can modify this however you like, but keep in mind the Twitter 140 character limit! If your message exceeds that after replacing the $ variables, then your tweet will fail. This will be reported in the HSLogFile if your debug level is set high enough. Once you're done modifying the message, save the file and start up HeroStats - your next tweet should use the new message!