mirror of
https://github.com/nikdoof/kosbot.git
synced 2025-12-11 17:42:15 +00:00
Fix some minor issues.
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -52,3 +52,6 @@ coverage.xml
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# IDEA
|
||||
.idea
|
||||
|
||||
|
||||
26
kosbot.py
26
kosbot.py
@@ -1,7 +1,11 @@
|
||||
import os
|
||||
import logging
|
||||
import sleekxmpp
|
||||
import requests
|
||||
from urlparse import urljoin
|
||||
try:
|
||||
from urlparse import urljoin
|
||||
except ImportError:
|
||||
from urllib.parse import urljoin
|
||||
|
||||
class KOSCheckBot(sleekxmpp.ClientXMPP):
|
||||
|
||||
@@ -27,13 +31,17 @@ class KOSCheckBot(sleekxmpp.ClientXMPP):
|
||||
args = msg['body'].split(' ')[1:]
|
||||
|
||||
if cmd == 'kos':
|
||||
return self.cmd_kos(msg, cmd, args)
|
||||
result = self.cmd_kos(msg, cmd, args)
|
||||
|
||||
def cmd_kos(self, msg, cmd, args)
|
||||
msg.reply(result).send()
|
||||
|
||||
def cmd_kos(self, msg, cmd, args):
|
||||
arg = ' '.join(args)
|
||||
resp = requests.get(urljoin(KOS_API_URL, params={
|
||||
resp = requests.get(self.KOS_API_URL, params={
|
||||
'c': 'json',
|
||||
'q': arg
|
||||
'q': arg,
|
||||
'type': 'unit',
|
||||
'details': None
|
||||
})
|
||||
if resp.status_code != requests.codes.ok:
|
||||
return "Something went wrong (Error %s)" % resp.status_code
|
||||
@@ -47,8 +55,8 @@ class KOSCheckBot(sleekxmpp.ClientXMPP):
|
||||
return "KOS returned no results (Not on KOS)"
|
||||
|
||||
results = []
|
||||
for result in data['results']
|
||||
text = '%s (%s) - %s'.format(
|
||||
for result in data['results']:
|
||||
text = '{} ({}) - {}'.format(
|
||||
result['label'],
|
||||
result['type'],
|
||||
'KOS' if result['kos'] else 'Not KOS'
|
||||
@@ -58,10 +66,12 @@ class KOSCheckBot(sleekxmpp.ClientXMPP):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
jid = os.environ.get('KOSBOT_JID')
|
||||
password = os.environ.get('KOSBOT_PASSWORD')
|
||||
nickname = os.environ.get('KOSBOT_NICKNAME', 'KOSBot')
|
||||
rooms = os.environ.get('KOSBOT_CHANNELS')
|
||||
rooms = os.environ.get('KOSBOT_ROOMS')
|
||||
|
||||
rooms = [x.strip() for x in rooms.split(',')]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user