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
|
# Sphinx documentation
|
||||||
docs/_build/
|
docs/_build/
|
||||||
|
|
||||||
|
# IDEA
|
||||||
|
.idea
|
||||||
|
|
||||||
|
|||||||
28
kosbot.py
28
kosbot.py
@@ -1,7 +1,11 @@
|
|||||||
import os
|
import os
|
||||||
|
import logging
|
||||||
import sleekxmpp
|
import sleekxmpp
|
||||||
import requests
|
import requests
|
||||||
from urlparse import urljoin
|
try:
|
||||||
|
from urlparse import urljoin
|
||||||
|
except ImportError:
|
||||||
|
from urllib.parse import urljoin
|
||||||
|
|
||||||
class KOSCheckBot(sleekxmpp.ClientXMPP):
|
class KOSCheckBot(sleekxmpp.ClientXMPP):
|
||||||
|
|
||||||
@@ -27,13 +31,17 @@ class KOSCheckBot(sleekxmpp.ClientXMPP):
|
|||||||
args = msg['body'].split(' ')[1:]
|
args = msg['body'].split(' ')[1:]
|
||||||
|
|
||||||
if cmd == 'kos':
|
if cmd == 'kos':
|
||||||
return self.cmd_kos(msg, cmd, args)
|
result = self.cmd_kos(msg, cmd, args)
|
||||||
|
|
||||||
|
msg.reply(result).send()
|
||||||
|
|
||||||
def cmd_kos(self, msg, cmd, args)
|
def cmd_kos(self, msg, cmd, args):
|
||||||
arg = ' '.join(args)
|
arg = ' '.join(args)
|
||||||
resp = requests.get(urljoin(KOS_API_URL, params={
|
resp = requests.get(self.KOS_API_URL, params={
|
||||||
'c': 'json',
|
'c': 'json',
|
||||||
'q': arg
|
'q': arg,
|
||||||
|
'type': 'unit',
|
||||||
|
'details': None
|
||||||
})
|
})
|
||||||
if resp.status_code != requests.codes.ok:
|
if resp.status_code != requests.codes.ok:
|
||||||
return "Something went wrong (Error %s)" % resp.status_code
|
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)"
|
return "KOS returned no results (Not on KOS)"
|
||||||
|
|
||||||
results = []
|
results = []
|
||||||
for result in data['results']
|
for result in data['results']:
|
||||||
text = '%s (%s) - %s'.format(
|
text = '{} ({}) - {}'.format(
|
||||||
result['label'],
|
result['label'],
|
||||||
result['type'],
|
result['type'],
|
||||||
'KOS' if result['kos'] else 'Not KOS'
|
'KOS' if result['kos'] else 'Not KOS'
|
||||||
@@ -58,10 +66,12 @@ class KOSCheckBot(sleekxmpp.ClientXMPP):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
|
||||||
jid = os.environ.get('KOSBOT_JID')
|
jid = os.environ.get('KOSBOT_JID')
|
||||||
password = os.environ.get('KOSBOT_PASSWORD')
|
password = os.environ.get('KOSBOT_PASSWORD')
|
||||||
nickname = os.environ.get('KOSBOT_NICKNAME', 'KOSBot')
|
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(',')]
|
rooms = [x.strip() for x in rooms.split(',')]
|
||||||
|
|
||||||
@@ -69,6 +79,6 @@ if __name__ == '__main__':
|
|||||||
bot.register_plugin('xep_0030') # Service Discovery
|
bot.register_plugin('xep_0030') # Service Discovery
|
||||||
bot.register_plugin('xep_0045') # Multi-User Chat
|
bot.register_plugin('xep_0045') # Multi-User Chat
|
||||||
bot.register_plugin('xep_0199') # XMPP Ping
|
bot.register_plugin('xep_0199') # XMPP Ping
|
||||||
|
|
||||||
if bot.connect():
|
if bot.connect():
|
||||||
bot.process(block=True)
|
bot.process(block=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user