-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a854b0c
commit 0d549f9
Showing
5 changed files
with
318 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System.Net; | ||
using BotNet.Commands.Khodam; | ||
using BotNet.Services.Khodam; | ||
using Telegram.Bot; | ||
using Telegram.Bot.Types.Enums; | ||
|
||
namespace BotNet.CommandHandlers.Khodam { | ||
public sealed class KhodamCommandHandler( | ||
ITelegramBotClient telegramBotClient | ||
) : ICommandHandler<KhodamCommand> { | ||
private readonly ITelegramBotClient _telegramBotClient = telegramBotClient; | ||
|
||
public async Task Handle(KhodamCommand command, CancellationToken cancellationToken) { | ||
string khodam = KhodamCalculator.CalculateKhodam( | ||
name: command.Name, | ||
userId: command.UserId | ||
); | ||
|
||
await _telegramBotClient.SendTextMessageAsync( | ||
chatId: command.Chat.Id, | ||
text: $$""" | ||
Khodam <b>{{WebUtility.HtmlEncode(command.Name)}}</b> hari ini adalah... | ||
<b>{{khodam}}</b> | ||
""", | ||
parseMode: ParseMode.Html, | ||
replyToMessageId: command.TargetMessageId, | ||
cancellationToken: cancellationToken | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using BotNet.Commands.BotUpdate.Message; | ||
using BotNet.Commands.ChatAggregate; | ||
|
||
namespace BotNet.Commands.Khodam { | ||
public sealed record KhodamCommand : ICommand { | ||
public MessageId TargetMessageId { get; } | ||
public ChatBase Chat { get; } | ||
public string Name { get; } | ||
public long UserId { get; } | ||
|
||
private KhodamCommand( | ||
MessageId targetMessageId, | ||
ChatBase chat, | ||
string name, | ||
long userId | ||
) { | ||
TargetMessageId = targetMessageId; | ||
Chat = chat; | ||
Name = name; | ||
UserId = userId; | ||
} | ||
|
||
public static KhodamCommand FromSlashCommand(SlashCommand slashCommand) { | ||
if (slashCommand.Command != "/khodam") { | ||
throw new ArgumentException("Command must be /khodam.", nameof(slashCommand)); | ||
} | ||
|
||
return new( | ||
targetMessageId: slashCommand.MessageId, | ||
chat: slashCommand.Chat, | ||
name: slashCommand.ReplyToMessage?.Sender.Name ?? slashCommand.Sender.Name, | ||
userId: slashCommand.ReplyToMessage?.Sender.Id ?? slashCommand.Sender.Id | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
using System; | ||
|
||
namespace BotNet.Services.Khodam { | ||
public static class KhodamCalculator { | ||
private static readonly string[] ANIMALS = [ | ||
"Anjing", | ||
"Ayam", | ||
"Bebek", | ||
"Beruang", | ||
"Buaya", | ||
"Elang", | ||
"Gajah", | ||
"Harimau", | ||
"Ikan Lohan", | ||
"Kadal", | ||
"Kalajengking", | ||
"Kambing", | ||
"Katak", | ||
"Kucing", | ||
"Kuda", | ||
"Lumba-Lumba", | ||
"Monyet", | ||
"Naga", | ||
"Serigala", | ||
"Singa", | ||
"Ular", | ||
]; | ||
|
||
private static readonly string[] ADJECTIVES = [ | ||
"Birahi", | ||
"Hitam", | ||
"Hutan", | ||
"Jawa", | ||
"Kalimantan", | ||
"Ngawi", | ||
"Nolep", | ||
"Pelangi", | ||
"Pemalas", | ||
"Pemarah", | ||
"Putih", | ||
"Sakti", | ||
"Sumatera", | ||
"Sunda", | ||
]; | ||
|
||
private static readonly string[] RARES = [ | ||
"Ayam Geprek", | ||
"Ban Serep", | ||
"Bintang Laut", | ||
"Bubur Ayam", | ||
"Dewi Bulan", | ||
"Es Cendol", | ||
"Gado-Gado", | ||
"Gitar Spanyol", | ||
"Gule Kambing", | ||
"Ikan Bakar", | ||
"Kambing Guling", | ||
"Kang Parkir Indomaret", | ||
"Klepon", | ||
"Kopi Hitam", | ||
"Kulit Pisang", | ||
"Lontong Balap", | ||
"Mie Ayam", | ||
"Nasi Padang", | ||
"Pempek Palembang", | ||
"Penjaga Hutan", | ||
"Pisang Goreng", | ||
"Raja Jin", | ||
"Ratu Pantai Selatan", | ||
"Rawon", | ||
"Rengginang", | ||
"Risoles", | ||
"Sate Ayam", | ||
"Sate Kambing", | ||
"Sendal Jepit", | ||
"Sop Buntut", | ||
"Soto Ayam", | ||
"Supra Geter", | ||
"Susu Jahe", | ||
"Tahu Bulat", | ||
"Tiang Listrik", | ||
"Ulat Keket", | ||
"Wayang Kulit", | ||
]; | ||
|
||
public static string CalculateKhodam(string name, long userId) { | ||
int hashCode = HashCode.Combine( | ||
value1: DateTimeOffset.UtcNow.ToOffset(TimeSpan.FromHours(7)).Date, | ||
value2: name, | ||
value3: userId | ||
); | ||
|
||
// Kosong vs isi | ||
if (hashCode % 9679 < 2000) { | ||
return "Kosong"; | ||
} | ||
|
||
// Rare | ||
if (hashCode % 631 > 600) { | ||
return RARES[hashCode % RARES.Length]; | ||
} | ||
|
||
// Animals | ||
return $"{ANIMALS[hashCode % ANIMALS.Length]} {ADJECTIVES[hashCode % ADJECTIVES.Length]}"; | ||
} | ||
} | ||
} |
Oops, something went wrong.