Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/texdarkstar/gw2-bot

This is an inheritable class for telnet robots, for playing godwars 2, written entirely in python. Cheers!
https://github.com/texdarkstar/gw2-bot

mud-client python-2

Last synced: about 1 month ago
JSON representation

This is an inheritable class for telnet robots, for playing godwars 2, written entirely in python. Cheers!

Awesome Lists containing this project

README

        

# Example usage:

```python
from time import sleep
from bot import Robot

class MyBot(Robot):
def init(self):
self.add_trigger(
regex=r"^You .*, '(.*)'$",
func=self.my_func,
name="my_func",
gag=True,
)

def my_func(self, robot, string, matches):
print "Matched: %s" % string

def do_something_once(self, robot, timer):
self.execute("say Hello world")
self.execute("say Hello again!")


def do_something_lots(self, robot, timer):
self.execute("say my timer ran %d time%s!" % (timer.runs, "s" if timer.runs > 1 else ""))


bot = MyBot("username", "password")

bot.connect()
sleep(2)

bot.add_timer(1, bot.do_something_once)
bot.add_timer(.1, bot.do_something_lots, max_runs=10)

bot.execute("finger %s" % bot.username)
bot.loop()
```

# Known quirks:
* The bot will not fire any triggers or write anything to the screen until you call its `loop()` function, which blocks the calling thread.

# Tips on usage:
* If you want to run a single script but use multiple Robots, you will need a structure like so:
```python
from bot import Robot
import threading

def start(bot):
bot.loop()

def main():
threads = []
characters = {"GuyOne": "hispass", "GuyTwo": "hispass"}
for name in characters:
bot = Robot(name, characters[name], silent=True) # Likely will want to set silent=True, otherwise you're gonna get the
bot.connect() # mud output for each guy written to the same screen.
thread = threading.Thread(target=start, args=(bot,))
thread.start()
threads.append(thread)
main()

```