12345678910111213141516171819202122232425262728 |
- # -*- coding: utf-8 -*-
-
- import socket
-
- import sardine
-
-
- class Plugin(sardine.BasePlugin):
-
- def _read_args(self):
- args = self.data.args[:]
- try:
- self.host = args.pop(0)
- self.port = args.pop(0) if args else 17
- except IndexError:
- raise sardine.SardinePluginUsageError("HOST [PORT]")
- self.port = int(self.port)
-
- def _fetch_qotd(self):
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- s.connect((self.host, self.port))
- self.qotd = s.recv(512).strip()
- s.close()
-
- def render_plain(self):
- self._read_args()
- self._fetch_qotd()
- return self.qotd
|