Skip to content

Commit

Permalink
Made hero job time dynamic and changed time for it
Browse files Browse the repository at this point in the history
  • Loading branch information
dmbaranov committed Sep 4, 2024
1 parent 0d0906e commit 6949ce4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
10 changes: 5 additions & 5 deletions assets/swearwords/swearwords.sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@
}
},
"hero": {
"users_at_five": {
"no_users": "В 5:00 онлайн пользователи отсутствуют",
"list": "Эти пользователи были онлайн в 5:00:\n",
"stats": "Эти пользователи чаще всего были онлайн в 5:00",
"hero_stats": "$hero был онлайн в 5:00 $count раз"
"active_users": {
"no_users": "В $hour:00 онлайн пользователи отсутствуют",
"list": "Эти пользователи были онлайн в $hour:00:\n",
"stats": "Эти пользователи чаще всего были онлайн в $hour:00",
"hero_stats": "$hero был онлайн в $hour:00 $count раз"
}
},
"conversator": {
Expand Down
18 changes: 11 additions & 7 deletions lib/src/platform/discord/discord_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ class DiscordModule {
}

void _startHeroCheckJob() {
Cron().schedule(Schedule.parse('0 5 * * 6,0'), () async {
const hour = 3;

Cron().schedule(Schedule.parse('0 $hour * * 6,0'), () async {
var authorizedChats = await modulesMediator.chat.getAllChatIdsForPlatform(ChatPlatform.discord);

await Future.forEach(authorizedChats, (chatId) async {
Expand All @@ -68,15 +70,17 @@ class DiscordModule {

var listOfOnlineUsers = chatOnlineUsers.entries.where((entry) => entry.value == true).map((entry) => entry.key).toList();
if (listOfOnlineUsers.isEmpty) {
return platform.sendMessage(chatId, translation: 'hero.users_at_five.no_users');
var noUsersMessage = _sw.getText(chatId, 'hero.active_users.no_users', {'hour': hour.toString()});

return platform.sendMessage(chatId, message: noUsersMessage);
}

var now = DateTime.now();
var timestamp = DateTime(now.year, now.month, now.day, 5).toString();
var timestamp = DateTime(now.year, now.month, now.day, hour).toString();
var chatUsers = await modulesMediator.user.getUsersForChat(chatId);
var chatUserStats = await _heroStatsDb.getChatHeroStats(chatId);
var heroesMessage = _sw.getText(chatId, 'hero.users_at_five.list');
var heroesStatsMessage = _sw.getText(chatId, 'hero.users_at_five.stats');
var heroesMessage = _sw.getText(chatId, 'hero.active_users.list', {'hour': hour.toString()});
var heroesStatsMessage = _sw.getText(chatId, 'hero.active_users.stats', {'hour': hour.toString()});

await Future.forEach(listOfOnlineUsers, (userId) async {
var onlineUser = chatUsers.firstWhereOrNull((user) => user.id == userId);
Expand All @@ -93,8 +97,8 @@ class DiscordModule {
var userData = chatUsers.firstWhereOrNull((user) => user.id == userStats.$1);

if (userData != null) {
heroesStatsMessage +=
_sw.getText(chatId, 'hero.users_at_five.hero_stats', {'hero': userData.name, 'count': userStats.$2.toString()});
heroesStatsMessage += _sw.getText(
chatId, 'hero.active_users.hero_stats', {'hero': userData.name, 'hour': hour.toString(), 'count': userStats.$2.toString()});
}
});

Expand Down

0 comments on commit 6949ce4

Please sign in to comment.