Skip to content

Commit

Permalink
feat: manual upload hunt (only front-end)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bluefissure committed Jun 11, 2022
1 parent bb1116c commit 2a51e0d
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ utils/secret/
.idea
*.swp
lib/
collectstatic/
8 changes: 4 additions & 4 deletions ffxivbot/handlers/QQCommand_market.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ def get_market_data(server_name, item_name, hq=False):
break
new_item_name, item_id = get_item_id(item_name, name_lang)
if item_id < 0:
msg = '所查询物品"{}"不存在'.format(item_name)
return msg
return '所查询物品"{}"不存在'.format(item_name)
url = "https://universalis.app/api/{}/{}".format(server_name, item_id)
print("market url:{}".format(url))
r = requests.get(url, timeout=3)
if r.status_code != 200:
if r.status_code == 404:
msg = "请确认所查询物品可交易且不可在NPC处购买\n"
msg += "Error of HTTP request (code {}):\n{}".format(r.status_code, r.text)
msg = "请确认所查询物品可交易且不可在NPC处购买"
else:
msg = "Error of HTTP request (code {}):\n{}".format(r.status_code, r.text)
return msg
j = r.json()
msg = "{} 的 {}{} 数据如下:\n".format(server_name, new_item_name, "(HQ)" if hq else "")
Expand Down
5 changes: 3 additions & 2 deletions ffxivbot/pika_rabbit.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,14 @@ def on_consumer_cancelled(self, method_frame):
self._channel.close()

def on_message(self, _unused_channel, basic_deliver, properties, body):
LOGGER.info('Received message # %s from %s: %s',
basic_deliver.delivery_tag, properties.app_id, body)
LOGGER.debug('Received message # %s: %s',
basic_deliver.delivery_tag, body)

try:
receive = json.loads(body)
receive["pika_time"] = time.time()
self_id = receive["self_id"]
LOGGER.info('Received message # %s from %s', basic_deliver.delivery_tag, self_id)
try:
bot = QQBot.objects.get(user_id=self_id)
except QQBot.DoesNotExist as e:
Expand Down
2 changes: 2 additions & 0 deletions ffxivbot/static/plugins/moment/moment.min.js

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

24 changes: 17 additions & 7 deletions ffxivbot/views/hunt.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import time
from datetime import datetime
from zoneinfo import ZoneInfo
from django.utils.timezone import make_aware
from django.contrib.auth.decorators import login_required
from django.db.models import Q, Max
from ffxivbot.models import Monster, HuntLog, HuntGroup
from ffxivbot.models import Monster, HuntLog, HuntGroup, Server
from .ren2res import ren2res
import traceback

Expand All @@ -16,14 +17,16 @@ def get_hms(seconds):
def gen_hunts(user, sonar=False):
hunt_list = []
resource_groups = set()
TIMEFORMAT_MDHMS = "%m-%d %H:%M:%S"
# TIMEFORMAT_MDHMS = "%m-%d %H:%M:%S"
if not sonar:
latest_kill_logs = HuntLog.objects.filter(
Q(hunt_group__group__member_list__contains=user.user_id, log_type='kill') | Q(hunt_group__public=True)
).values('server__name', 'monster', 'hunt_group', 'instance_id').annotate(Max('time'))
else:
latest_kill_logs = HuntLog.objects.filter(log_type='sonar')\
latest_kill_logs = HuntLog.objects.filter(log_type='sonar', time__gt=time.time()-3600*24*7*2)\
.values('server__name', 'monster', 'instance_id').annotate(Max('time'))

print(f"#latest_kill_logs:{latest_kill_logs.count()}")
maintain_logs = HuntLog.objects.filter(log_type='maintain').values('server__name').annotate(Max('time'))
server_maintains = {}
for log in maintain_logs:
Expand Down Expand Up @@ -92,9 +95,9 @@ def gen_hunts(user, sonar=False):
monster_info["spawn_deltaf"] = spawn_deltaf
monster_info["spawn_delta"] = spawn_delta
monster_info["in_cd"] = in_cd
monster_info["kill_time"] = make_aware(datetime.fromtimestamp(kill_time))
monster_info["next_spawn_time"] = make_aware(datetime.fromtimestamp(next_spawn_time))
monster_info["next_pop_time"] = make_aware(datetime.fromtimestamp(next_pop_time))
monster_info["kill_timestamp"] = kill_time
monster_info["next_spawn_timestamp"] = next_spawn_time
monster_info["next_pop_timestamp"] = next_pop_time
monster_info["info"] = monster.info
monster_info["resource"] = str(hunt_group)
hunt_list.append(monster_info)
Expand All @@ -111,7 +114,14 @@ def hunt(req):
#@login_required(login_url='/login/')
def hunt_sonar(req):
hunt_list, resource_groups = gen_hunts(None, True)
return ren2res('hunt.html', req, {"hunt_list": hunt_list, "resources": ", ".join(list(resource_groups))})
monster_list = sorted([x['cn_name'] for x in Monster.objects.all().values('cn_name')])
server_list = [x['name'] for x in Server.objects.all().values('name')]
return ren2res('hunt.html', req, {
"hunt_list": hunt_list,
"monster_list": monster_list,
"server_list": server_list,
"resources": ", ".join(list(resource_groups)),
})

NAME_TAG = {
"红玉海":"hyh",
Expand Down
2 changes: 2 additions & 0 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@

<!-- Google Font: Source Sans Pro -->
<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">
{% block head %}
{% endblock %}
</head>
<body class="hold-transition sidebar-mini">
{% block main %}
Expand Down
Loading

0 comments on commit 2a51e0d

Please sign in to comment.