Alois Mahdal 10 anni fa
parent
commit
cb5fbab7fe
1 ha cambiato i file con 28 aggiunte e 0 eliminazioni
  1. 28
    0
      plugins/qotd.py

+ 28
- 0
plugins/qotd.py Vedi File

@@ -0,0 +1,28 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+import socket
4
+
5
+import sardine
6
+
7
+
8
+class Plugin(sardine.BasePlugin):
9
+
10
+    def _read_args(self):
11
+        args = self.data.args[:]
12
+        try:
13
+            self.host = args.pop(0)
14
+            self.port = args.pop(0) if args else 17
15
+        except IndexError:
16
+            raise sardine.SardinePluginUsageError("HOST [PORT]")
17
+        self.port = int(self.port)
18
+
19
+    def _fetch_qotd(self):
20
+        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
21
+        s.connect((self.host, self.port))
22
+        self.qotd = s.recv(512).strip()
23
+        s.close()
24
+
25
+    def render_plain(self):
26
+        self._read_args()
27
+        self._fetch_qotd()
28
+        return self.qotd