Skip to content
Permalink
Browse files
Extremely WIP stub of a Pokémon Showdown client, and a bad bot plugin
  • Loading branch information
eevee committed Jun 4, 2016
1 parent ad148a3 commit ff88005bd78e9054ce61de54a8b1d2bb3de70777
Show file tree
Hide file tree
Showing 4 changed files with 379 additions and 3 deletions.
@@ -6,6 +6,7 @@
from urllib.parse import urlparse

from dywypi.dialect.irc.client import IRCClient
from dywypi.dialect.showdown.client import ShowdownClient
from dywypi.plugin import PluginManager
from dywypi.state import Network
from dywypi.state import Server
@@ -25,6 +26,9 @@ def __init__(self):
self.networks = {}
self.plugin_manager = PluginManager()

# TODO TODO TODO FOR REAL NEXT THING: build that magical argparse env ini
# yaml config whatever thing and use it here where it's kind of more
# immediately urgent
def configure_from_argv(self, argv=None):
# Scan for known plugins first
self.plugin_manager.scan_package('dywypi.plugins')
@@ -141,6 +145,8 @@ def add_adhoc_connection(self, uristr):
# TODO dying for some registration here.
if uri.scheme in ('irc', 'ircs'):
client_class = IRCClient
elif uri.scheme in ('showdown',):
client_class = ShowdownClient
elif uri.scheme in ('shell',):
# TODO import down here in case no urwid
from dywypi.dialect.shell import ShellClient
@@ -164,6 +170,7 @@ def add_adhoc_connection(self, uristr):

# TODO hmm should this stuff be delegated to a dialect? some of it may
# not make sense for some dialects
# TODO for example, it makes no sense for showdown
network = Network(name)
if uri.username:
network.add_preferred_nick(uri.username)
@@ -238,7 +238,7 @@ def unhandled_input(self, key):
key = self.pane.keypress(listsize, key)
if key:
# `key` gets returned if it wasn't consumed
self.add_log_line(key)
self.add_log_line(repr(key))

def add_log_line(self, line, color='default'):
# TODO generalize this color thing in a way compatible with irc, html, ...
@@ -249,8 +249,6 @@ def add_log_line(self, line, color='default'):
def _print_text(self, *encoded_text):
self.pane.body.append(urwid.Text(list(encoded_text)))
self.pane.set_focus(len(self.pane.body) - 1)
# TODO should this just mark dirty??
self.urwid_loop.draw_screen()

def handle_line(self, line):
"""Deal with a line of input."""
@@ -277,6 +275,18 @@ def _handle_line(self, line):
event = Message(self, raw_message)
self.event_queue.put_nowait(event)

elif line.startswith('>'):
text = line[1:]
# TODO LOL THIS IS REAL BAD
from __main__ import brain
for client in brain.current_clients:
if type(client).__name__ == 'ShowdownClient':
break
asyncio.ensure_future(client.send_raw(client._current_room, text))

# TODO need a way to generally use my own api


def _send_message(self, target, message, as_notice=True):
# TODO cool color
self.add_log_line(message)
Empty file.

0 comments on commit ff88005

Please sign in to comment.