Skip to content

Commit

Permalink
add grafana
Browse files Browse the repository at this point in the history
  • Loading branch information
Bluefissure committed Apr 4, 2019
1 parent 95af85c commit 8428695
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 24 deletions.
2 changes: 2 additions & 0 deletions FFXIV/settings_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,5 @@
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
]

USE_GRAFANA = False
8 changes: 8 additions & 0 deletions ffxivbot/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,3 +365,11 @@ class ContentFinderItem(models.Model):

def __str__(self):
return self.name

class CommandLog(models.Model):
time = models.BigIntegerField(default=0)
command = models.CharField(max_length=32)
message = models.TextField(default="")
bot_id = models.CharField(max_length=16)
user_id = models.CharField(max_length=16)
group_id = models.CharField(max_length=16)
81 changes: 57 additions & 24 deletions ffxivbot/pika_rabbit.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
import ffxivbot.handlers as handlers
from ffxivbot.models import *


USE_GRAFANA = getattr(settings, "USE_GRAFANA", False)


CONFIG_PATH = os.environ.get(
"FFXIVBOT_CONFIG", os.path.join(FFXIVBOT_ROOT, "ffxivbot/config.json")
)
Expand Down Expand Up @@ -558,6 +562,16 @@ def on_message(self, unused_channel, basic_deliver, properties, body):
group_commands=handlers.group_commands,
alter_commands=handlers.alter_commands,
)
if USE_GRAFANA:
command_log = CommandLog(
time = int(time.time()),
bot_id = str(self_id),
user_id = str(user_id),
group_id = str(group_id),
command = str(command_key),
message = receive["message"]
)
command_log.save()
for action in action_list:
call_api(
bot,
Expand All @@ -570,25 +584,7 @@ def on_message(self, unused_channel, basic_deliver, properties, body):
if already_reply:
break

if not already_reply:
action_list = handlers.QQGroupChat(
receive=receive,
global_config=config,
bot=bot,
user_info=user_info,
member_list=member_list,
group=group,
commands=handlers.commands,
alter_commands=handlers.alter_commands,
)
for action in action_list:
call_api(
bot,
action["action"],
action["params"],
echo=action["echo"],
post_type=receive.get("reply_api_type", "websocket")
)


if receive["message"].find("/help") == 0:
msg = ""
Expand Down Expand Up @@ -627,18 +623,23 @@ def on_message(self, unused_channel, basic_deliver, properties, body):
and group_commands[command_key] == "disable"
):
continue
LOGGER.debug(
"{} calling command: {}".format(user_id, command_key)
)
handle_method = getattr(
handlers,
"QQCommand_{}".format(command_key.replace("/", "", 1)),
)
action_list = handle_method(
receive=receive, global_config=config, bot=bot
)
# if(len(json.loads(bot.disconnections))>100):
# action_list = self.intercept_action(action_list)
if USE_GRAFANA:
command_log = CommandLog(
time = int(time.time()),
bot_id = str(self_id),
user_id = str(user_id),
group_id = "private" if receive["message_type"] != "group" else str(group_id),
command = str(command_key),
message = receive["message"]
)
command_log.save()
for action in action_list:
call_api(
bot,
Expand All @@ -650,6 +651,38 @@ def on_message(self, unused_channel, basic_deliver, properties, body):
already_reply = True
break

# handling chat
if receive["message_type"] == "group":
if not already_reply:
action_list = handlers.QQGroupChat(
receive=receive,
global_config=config,
bot=bot,
user_info=user_info,
member_list=member_list,
group=group,
commands=handlers.commands,
alter_commands=handlers.alter_commands,
)
if USE_GRAFANA:
command_log = CommandLog(
time = int(time.time()),
bot_id = str(self_id),
user_id = str(user_id),
group_id = "private" if receive["message_type"] != "group" else str(group_id),
command = "/chat",
message = receive["message"]
)
command_log.save()
for action in action_list:
call_api(
bot,
action["action"],
action["params"],
echo=action["echo"],
post_type=receive.get("reply_api_type", "websocket")
)

CONFIG_GROUP_ID = config["CONFIG_GROUP_ID"]
if receive["post_type"] == "request":
if receive["request_type"] == "friend": # Add Friend
Expand Down

0 comments on commit 8428695

Please sign in to comment.