Programming Haskell Pokemon Showdown bot "library"

This is really only a library in the literal sense, because the only thing you get to do is call a bot-making function on a configuration. But this configuration can contain any number of triggers (similar to the ruby bot), which are pluginey things that will react to messages received from the server.

Repo (Github): https://github.com/raymoo/needles
Docs: https://hackage.haskell.org/package/needles-0.1.0.0/candidate

There are already a ton of PS bots, but this one has some benefits:
  • Static typing - The other bots I have seen are written in languages with no static types, meaning that it is easier for bugs to go undetected, only to blow up while you are using your bot. Haskell's type system is very powerful and can encode many useful invariants.
  • Syntax - Haskell has wonderful syntax
  • Pure functional language - Haskell requires explicit mention of effects, which reduces the confusion and error resulting from trying to reason about side-effects and mutation
  • Libraryish - You can run a pokemon showdown bot as part of another program. If you want, arbitrary IO actions can be lifted into the TriggerAction type, so you can interface your bot with other parts of your program (through some kind of concurrency).
How to use?

The main driver of this library is the runBot function. You pass it a configuration, and it gives you back an IO action that will run your bot when executed. Here is what an example configuration might look like:
Code:
config :: Configuration
config =
  Configuration { cUsername = "Botbot"
                , cPassword = "Botpass"
                , cServer   = mainServer
                , cPort     = mainPort
                , cPath     = mainPath
                , cRooms    = ["techcode", "animeandmanga"]
                , cTriggers = [ replyTrig, replyPmTrig, simpleStateTrig, stateTrig ]
                }
This configuration would log in to the main pokemon showdown server as "Botbot" with the password "Botpass", and join the techcode and animeandmanga rooms. It would also have the example triggers turned on. The definitions for the triggers and main* are in the documentation for Needles.Bot.Trigger.Examples and Needles.Bot.Configuration, respectively.

You can create a bot like this:
Code:
myBot :: IO ()
myBot = runBot config
You could make this your main, or you could make it part of some larger program.

If you were really lazy, you could even run a bot from a repl:
Code:
Haskell>:m +Needles.Bot.Configuration Needles.Bot.Trigger Needles.Bot.Trigger.Examples Needles.Bot
Haskell>let config = Configuration { cUsername = "Takbir", cPassword = "*******", cServer = mainServer, cPort = mainPort, cPath = mainPath, cRooms = ["techcode"], cTriggers = [ replyTrig, replyPmTrig, simpleStateTrig, stateTrig] }
Haskell>runBot config
Connected
Unhandled Message
Unhandled Message
Unhandled Message
Received Challenge - Logging in
Logged In
Joining Rooms...
Done.
Unhandled Message
Unhandled Message
Unhandled Message
Unhandled Message
Unhandled Message
Unhandled Message
Unhandled Message
For how to make triggers, refer to the documentation for Needles.Bot.Trigger and the source code for the example triggers.
 
Last edited:

Users Who Are Viewing This Thread (Users: 1, Guests: 0)

Top