def __init__(self): config = configparser.RawConfigParser() config.read('conf/lol_chat_service.conf') user = config.get('LolAccount', 'user') passwd = config.get('LolAccount', 'pass') region = config.get('LolAccount', 'region') logging.getLogger('sleekxmpp').setLevel(logging.DEBUG) self.bot = Xmppbot(user, passwd, region, self.index_message) self.bot.connect()
class LolChatService: def __init__(self): config = configparser.RawConfigParser() config.read('conf/lol_chat_service.conf') user = config.get('LolAccount', 'user') passwd = config.get('LolAccount', 'pass') region = config.get('LolAccount', 'region') logging.getLogger('sleekxmpp').setLevel(logging.DEBUG) self.bot = Xmppbot(user, passwd, region, self.index_message) self.bot.connect() def index_message(self, message): elastic = elasticsearch.Elasticsearch() try: message_id = message['id'] mucnick = message['mucnick'] mucroom = message['mucroom'] body = message['body'] timestamp = datetime.utcnow() elastic.index(index='lol_chat', doc_type='chat_message', body={"message_id": message_id, "mucnick": mucnick, "mucroom": mucroom, "body": body, "timestamp": timestamp}) except: traceback.print_exc() def setup_index(self): elastic = elasticsearch.Elasticsearch() try: mapping = { "chat_message": { "properties": { "message_id": {"type": "string"}, "mucnick": {"type": "string", "index": "not_analyzed"}, "mucroom": {"type": "string"}, "body": {"type": "string"}, "timestamp": {"type": "date"}, } } } elastic.indices.create("lol_chat") elastic.indices.put_mapping(index="lol_chat", doc_type="chat_message", body=mapping) except: traceback.print_exc() def join_channel(self, channel): self.bot.join_muc_room(channel) def leave_channel(self, channel): self.bot.leave_muc_room(channel)