public static long getbet(Message mess) { bool hasEnoughMoney(Message mess, long bet) { if (BotMain.users.FirstOrDefault(m => m.id == mess.From.Id).balance >= bet) { return(true); } else { return(false); } } long bet = 0; try { bet = long.Parse(mess.Text.Split(" ")[1]); if (bet < 0) { bet = 0; } } catch (Exception e) { Other.OnReceivedError(e, mess, ""); bet = 500; } if (hasEnoughMoney(mess, bet)) { return(bet); } return(-1); }
public static async void messageto(Message mess) { try { await BotMain.bot.SendTextMessageAsync(long.Parse(mess.Text.Split(' ')[1]), string.Join(' ', mess.Text.Split(' ').Skip(2))); } catch (Exception e) { Other.OnReceivedError(e, mess); } }
public static async void balance(Message mess) { try { await BotMain.bot.SendTextMessageAsync(mess.Chat.Id, $"Ваш баланс: {BotMain.users.FirstOrDefault(m => m.id == mess.From.Id).balance:N0} тийин.\n<b>!бонус</b> для получения дополнительных монет.", ParseMode.Html); } catch (Exception e) { Other.OnReceivedError(e, mess); } }
public static async void kickUser(Message mess) { try { await BotMain.bot.KickChatMemberAsync(mess.ReplyToMessage.Chat.Id, mess.ReplyToMessage.From.Id); } catch (Exception e) { Other.OnReceivedError(e, mess); } }
public static async void getInfo(Message mess) { try { await BotMain.bot.SendTextMessageAsync(mess.Chat.Id, JsonConvert.SerializeObject(mess.ReplyToMessage, Formatting.Indented)); } catch (Exception e) { Other.OnReceivedError(e, mess); } }
public static async void deleteMessage(Message mess) { try { await BotMain.bot.DeleteMessageAsync(mess.ReplyToMessage.Chat.Id, mess.ReplyToMessage.MessageId); } catch (Exception e) { Other.OnReceivedError(e, mess); } }
public static async void start(Message mess) { try { string text = "Многофункциональный бот, в котором имеются игры, разные приколюхи, а также некоторый функционал для osu!\nВведите <b>/help</b> для получения <i>всех</i> функций бота."; await BotMain.bot.SendTextMessageAsync(mess.Chat.Id, text, ParseMode.Html); } catch (Exception e) { Other.OnReceivedError(e, mess); } }
public static async void flip(Message mess) { try { string name = $"{mess.From.FirstName} {mess.From.LastName}"; await BotMain.bot.SendTextMessageAsync(mess.Chat.Id, $"{name} подбрасывает монету: <b>{new string[] { "орёл", "решка" }[RandomNumberGenerator.GetInt32(0, 2)]}</b>", ParseMode.Html); } catch (Exception e) { Other.OnReceivedError(e, mess); } }
public static async void subscribe(Message mess) { try { var find = BotMain.groups.IndexOf(BotMain.groups.FirstOrDefault(m => m.id == mess.Chat.Id)); BotMain.groups[find].notifyOsu = !BotMain.groups[find].notifyOsu; await BotMain.bot.SendTextMessageAsync(mess.Chat.Id, $"{BotMain.groups[find].notifyOsu}"); } catch (Exception e) { Other.OnReceivedError(e, mess); } }
public static async void report(Message mess) { try { await BotMain.bot.SendTextMessageAsync(mess.Chat.Id, "Жалоба была успешно отправлена создателю."); await BotMain.bot.ForwardMessageAsync(BotMain.creatorId, mess.Chat.Id, mess.MessageId); } catch (Exception e) { Other.OnReceivedError(e, mess); } }
public static async void osuRemove(Message mess) { try { string name = string.Join(' ', mess.Text.Split(' ').Skip(1)); BotMain.osuUserTGs.Remove(BotMain.osuUserTGs.First(m => m.name == name)); await BotMain.bot.SendTextMessageAsync(mess.Chat.Id, $"{name} удален"); } catch (Exception e) { Other.OnReceivedError(e, mess); } }
public static async void random(Message mess) { try { GroupCollection numbers = new Regex(@"(\d*)-(\d*)").Match(mess.Text).Groups; int a = int.Parse(numbers[1].Value); int b = int.Parse(numbers[2].Value); await BotMain.bot.SendTextMessageAsync(mess.Chat.Id, $"<i>от {a} до {b}:</i>\n<b>{RandomNumberGenerator.GetInt32(a, b + 1)}</b>", ParseMode.Html); } catch (Exception e) { Other.OnReceivedError(e, mess); await BotMain.bot.SendTextMessageAsync(mess.Chat.Id, $"<i>от {0} до {100}:</i>\n<b>{RandomNumberGenerator.GetInt32(0, 100 + 1)}</b>", ParseMode.Html); } }
public static async void getCard(Message mess) { try { string name = string.Join(' ', mess.Text.Split(' ').Skip(1)); ImageWorker.GetBitmap($@"E:\{name}.png", ImageFormat.Png, name); InputOnlineFile card = new InputOnlineFile(new MemoryStream(System.IO.File.ReadAllBytes($@"E:\{name}.png"))); await BotMain.bot.SendPhotoAsync(mess.Chat.Id, card); } catch (Exception e) { Other.OnReceivedError(e, mess); } }
public static async void help(Message mess) { try { string text = "<b>!osu</b> [name] - <i>вывести инфу о вашем профиле</i>\n" + "<b>!rs</b> [count] - <i>вывести count последних скоров</i>\n" + ""; await BotMain.bot.SendTextMessageAsync(mess.Chat.Id, text, ParseMode.Html); } catch (Exception e) { Other.OnReceivedError(e, mess); } }
public static async void getListOsuTG(Message mess) { try { string text = ""; for (int i = 0; i <= BotMain.osuUserTGs.Count - 1; i++) { text += $"{BotMain.osuUserTGs[i].name}\n{BotMain.osuUserTGs[i].lastCheckedScore}\n\n"; } await BotMain.bot.SendTextMessageAsync(mess.Chat.Id, text); } catch (Exception e) { Other.OnReceivedError(e, mess); } }
public static async void osuAdd(Message mess) { try { string name = string.Join(' ', mess.Text.Split(' ').Skip(1)); if (BotMain.osuUserTGs.FirstOrDefault(m => m.name == name) == default) { BotMain.osuUserTGs.Add(new tgbot_final.Bot.Types.OsuUserTG { id = mess.From.Id, name = name }); } await BotMain.bot.SendTextMessageAsync(mess.Chat.Id, $"{name} добавлен"); } catch (Exception e) { Other.OnReceivedError(e, mess); } }
public static async void osu(Message mess) { try { osuApi osuApi = new osuApi(BotMain.osuToken); string name = string.Join(' ', mess.Text.Split(' ').Skip(1)); if (name == "") { await BotMain.bot.SendTextMessageAsync(mess.Chat.Id, "а ты кто?\n!osu [name]"); return; } User user = await osuApi.GetUserInfoByNameAsync(name); string text = $"<b>{name}'s profile!\n\nMain Information:</b>\n<code>join_date: {user.join_date:G}\ncountry: {user.country}" + $"\npp: {Convert.ToDouble(user.pp_raw):N0}pp\naccuracy: {double.Parse(user.accuracy):N2}%\nglobal_rank: #{user.pp_rank}" + $"\ncountry_rank: #{user.pp_country_rank}\nplaycount: {user.playcount}\nlevel: {double.Parse(user.level):N0}</code>"; int count = 0; text += $"\n\n<b>Top Plays:</b>\n<code>"; Score[] topscores = await osuApi.GetTopPlaysByNameAsync(name); foreach (var item in topscores) { count++; Mods mods = (Mods)osuApi.CalculateModsMods(int.Parse(item.enabled_mods)); double accuracy = (50 * double.Parse(item.count50) + 100 * double.Parse(item.count100) + 300 * double.Parse(item.count300)) / (300 * (double.Parse(item.countmiss) + double.Parse(item.count50) + double.Parse(item.count100) + double.Parse(item.count300))) * 100; Beatmap curBeatmap = await osuApi.GetBeatmapByBeatmapIdAsync(int.Parse(item.beatmap_id)); text += $"{count}. </code><b>({item.rank})</b><a href=\"https://osu.ppy.sh/beatmaps/{curBeatmap.beatmap_id}\">{curBeatmap.title} [{curBeatmap.version}]</a><code>\n {item.count300}-{item.count100}-{item.count50}-{item.countmiss}❌ - {accuracy:N2}%" + $"\n <b>{mods}</b> <i>{item.maxcombo}/{curBeatmap.max_combo}</i> <b><u>{item.pp:N0}pp</u></b>\n{DateTimeOffset.Parse(item.date).AddHours(5):dd.MM.yyyy HH:mm}\n\n"; if (count == 5) { break; } } text += "</code>"; await BotMain.bot.SendTextMessageAsync(mess.Chat.Id, text, ParseMode.Html); } catch (Exception e) { Other.OnReceivedError(e, mess); } }
public static async void bonusBalance(Message mess) { try { if (BotMain.users.FirstOrDefault(m => m.id == mess.From.Id).balance < 500) { BotMain.users.FirstOrDefault(m => m.id == mess.From.Id).balance += 500; await BotMain.bot.SendTextMessageAsync(mess.Chat.Id, "Вы получили 500 тийин"); } else { await BotMain.bot.SendTextMessageAsync(mess.Chat.Id, "Для получения бонусных монет, нужно иметь меньше, чем 500 тийин"); } } catch (Exception e) { Other.OnReceivedError(e, mess); } }
public static async void top(Message mess) { try { BotMain.users = BotMain.users.OrderBy(m => m.balance).ToList(); string text = "Топ богатых игроков в этой группе:\n"; int i = 1; foreach (var item in BotMain.users) { Chat chat = await BotMain.bot.GetChatAsync(item.id); string name = $"{chat.FirstName} {chat.LastName}"; text += $"<b>{i}</b>. <i>{name}</i> -=<code>{item.balance}</code>=-\n"; i += 1; } await BotMain.bot.SendTextMessageAsync(mess.Chat.Id, text, ParseMode.Html); } catch (Exception e) { Other.OnReceivedError(e, mess); } }
public static async void scores(Message mess) { try { osuApi osuapi = new osuApi(BotMain.osuToken); string beatmap_id = ""; for (int i = mess.Text.Length - 1; i >= 0; i--) { if (mess.Text[i] != '/') { beatmap_id = beatmap_id.Insert(0, mess.Text[i].ToString()); } else { break; } } string name = string.Join(" ", mess.Text.Split(" ").Skip(1).SkipLast(1)); Score[] scores = await osuapi.GetScoresOnMapByName(name, long.Parse(beatmap_id)); string text = ""; foreach (var item in scores) { Mods mods = (Mods)osuapi.CalculateModsMods(int.Parse(item.enabled_mods)); double accuracy = (50 * double.Parse(item.count50) + 100 * double.Parse(item.count100) + 300 * double.Parse(item.count300)) / (300 * (double.Parse(item.countmiss) + double.Parse(item.count50) + double.Parse(item.count100) + double.Parse(item.count300))) * 100; Beatmap beatmap = await osuapi.GetBeatmapByBeatmapIdAsync(int.Parse(beatmap_id)); double curpp = Other.ppCalc(beatmap, accuracy, mods, int.Parse(item.countmiss), int.Parse(item.maxcombo)); double IfFCpp = Other.ppCalc(beatmap, accuracy, mods, 0, int.Parse(beatmap.max_combo)); text += $"<b>({item.rank})</b> <a href=\"https://osu.ppy.sh/beatmaps/{item.beatmap_id}\">{beatmap.title} [{beatmap.version}]</a> <b>({beatmap.GetApproved()})</b>\n" + $"{item.count300}-{item.count100}-{item.count50}-{item.countmiss}❌ - <b><i>{accuracy:N2}</i></b>%\n" + $"<b>{mods}</b> <i>{item.maxcombo}/{beatmap.max_combo}</i> <b><u>{curpp:N0}pp</u></b> (<b><u>~{IfFCpp:N0}pp</u></b> if FC)\n({DateTimeOffset.Parse(item.date).AddHours(5):dd.MM.yyyy HH:mm})\n\n"; } await BotMain.bot.SendTextMessageAsync(mess.Chat.Id, text, ParseMode.Html); } catch (Exception e) { Other.OnReceivedError(e, mess, "Нет скоров"); } }
public static async void rs(Message mess) { try { string text = ""; osuApi osuApi = new osuApi(BotMain.osuToken); string name = string.Join(' ', mess.Text.Split(' ').Skip(1)); if (name == "") { await BotMain.bot.SendTextMessageAsync(mess.Chat.Id, "а ты кто?\n!rs [name]"); return; } Score recentScore = (await osuApi.GetRecentScoresByNameAsync(name))[0]; if (recentScore == default) { throw new FormatException(); } Beatmap beatmap = await osuApi.GetBeatmapByBeatmapIdAsync(long.Parse(recentScore.beatmap_id)); Mods mods = (Mods)osuApi.CalculateModsMods(int.Parse(recentScore.enabled_mods)); double accuracy = (50 * double.Parse(recentScore.count50) + 100 * double.Parse(recentScore.count100) + 300 * double.Parse(recentScore.count300)) / (300 * (double.Parse(recentScore.countmiss) + double.Parse(recentScore.count50) + double.Parse(recentScore.count100) + double.Parse(recentScore.count300))) * 100; double curpp = Other.ppCalc(beatmap, accuracy, mods, int.Parse(recentScore.countmiss), int.Parse(recentScore.maxcombo)); double ppIFfc = Other.ppCalc(beatmap, accuracy, mods, 0, int.Parse(beatmap.max_combo)); text += $"<b>({recentScore.rank})</b> <a href=\"https://osu.ppy.sh/beatmaps/{beatmap.beatmap_id}\">{beatmap.title} [{beatmap.version}]</a> <b>({beatmap.GetApproved()})</b>\n" + $"{recentScore.count300}-{recentScore.count100}-{recentScore.count50}-{recentScore.countmiss}❌ - <b><i>{accuracy:N2}</i></b>%\n" + $"<b>{mods}</b> <i>{recentScore.maxcombo}/{beatmap.max_combo}</i> <b><u>{curpp:N0}pp</u></b> (<b><u>~{ppIFfc:N0}pp</u></b> if FC)\n({DateTimeOffset.Parse(recentScore.date).AddHours(5):dd.MM.yyyy HH:mm})\n\n"; await BotMain.bot.SendTextMessageAsync(mess.Chat.Id, text, ParseMode.Html); } catch (FormatException e) { Other.OnReceivedError(e, mess, "Он ничего не играл последние 24 часа."); } catch (Exception e) { Other.OnReceivedError(e, mess, "Чет не получилось :("); } }
public static async void AllGroups(Message mess) { try { string[] ab = mess.Text.Split(" "); string text = ""; if (ab[1] == "all") { int count = 0; for (int i = 0; i <= BotMain.groups.Count - 1; i++) { try { count += 1; var t = await BotMain.bot.GetChatAsync(BotMain.groups[i].id); text += $"{count}. {t.Title} [{i}]\n"; } catch (Exception) { BotMain.groups.RemoveAt(i); i--; } } await BotMain.bot.SendTextMessageAsync(mess.Chat.Id, text); } else if (ab[1] == "toall") { for (int i = 0; i <= BotMain.groups.Count - 1; i++) { if (BotMain.groups[i].id.ToString().StartsWith("-100")) { try { await BotMain.bot.SendTextMessageAsync(BotMain.groups[i].id, string.Join(" ", ab.Skip(2))); } catch (Exception) { BotMain.groups.RemoveAt(i); i--; } } } } else if (ab[1] == "to") { try { await BotMain.bot.SendTextMessageAsync(BotMain.groups[int.Parse(ab[2])].id, string.Join(" ", ab.Skip(3))); } catch (Exception) { } } else if (ab[1] == "replyto") { try { Message messreply = mess.ReplyToMessage; string caption = ""; if (mess.ReplyToMessage.Photo != null) { if (mess.ReplyToMessage.Caption != null) { caption = mess.ReplyToMessage.Caption; } await BotMain.bot.SendPhotoAsync(BotMain.groups[int.Parse(ab[2])].id, new InputOnlineFile(mess.ReplyToMessage.Photo[0].FileId), caption : caption); } else if (mess.ReplyToMessage.Sticker != null) { await BotMain.bot.SendStickerAsync(BotMain.groups[int.Parse(ab[2])].id, new InputOnlineFile(mess.ReplyToMessage.Sticker.FileId)); } else if (mess.ReplyToMessage.Video != null) { if (mess.ReplyToMessage.Caption != null) { caption = mess.ReplyToMessage.Caption; } await BotMain.bot.SendVideoAsync(BotMain.groups[int.Parse(ab[2])].id, new InputOnlineFile(mess.ReplyToMessage.Video.FileId), caption : caption); } } catch (Exception) { } } else if (ab[1] == "fromall") { for (int i = 0; i <= BotMain.groups.Count - 1; i++) { if (BotMain.groups[i].id.ToString().StartsWith("-100")) { try { await BotMain.bot.SendTextMessageAsync(BotMain.groups[i].id, string.Join(" ", ab.Skip(2))); await BotMain.bot.LeaveChatAsync(BotMain.groups[i].id); BotMain.groups.RemoveAt(i); } catch (Exception) { BotMain.groups.RemoveAt(i); i--; } } } } else if (ab[1] == "from") { try { int ind = int.Parse(ab[2]); if (ab.Length >= 4) { await BotMain.bot.SendTextMessageAsync(BotMain.groups[ind].id, string.Join(" ", ab.Skip(3))); } await BotMain.bot.LeaveChatAsync(BotMain.groups[ind].id); BotMain.groups.RemoveAt(ind); } catch (Exception) { } } else if (ab[1] == "remove") { BotMain.groups.RemoveAt(int.Parse(ab[2])); } } catch (Exception e) { Other.OnReceivedError(e, mess, ""); await BotMain.bot.SendTextMessageAsync(mess.Chat.Id, "/groups\nremove [index] - del from bd\nfrom [ind] [mes] - leave + send mes\nfromall [mes] - leave from all + send mes\nto [ind] [mes] - send mes to group\ntoall [mes] - send mes to all groups\nall - get groups index"); } }
public static async void bandit(Message mess) { try { long bet = Other.getbet(mess); if (bet == -1) { await BotMain.bot.SendTextMessageAsync(mess.Chat.Id, "Кажется, что у вас не хватает монет, либо ставка слишком велика / неправильный формат ставки"); return; } string name = $"{mess.From.FirstName} {mess.From.LastName}"; string text = $"{name}:Ставка {bet}\n[🎁][🎁][🎁]"; string[] emoji = new string[18] { "👻", "🎱", "💥", "🍄", "🦆", "🐴", "🌑", "🤡", "🌕", "🌒", "🌖", "🌓", "🐞", "🐭", "🎢", "⚡️", "💊", "💣" }; double coff = 1; Message bandit = await BotMain.bot.SendTextMessageAsync(mess.Chat.Id, text); for (int i = 0; i <= 2; i++) { int rnd = RandomNumberGenerator.GetInt32(0, 18); if (emoji[rnd] == "🌑") { coff = (coff * 0.5); } else if (emoji[rnd] == "🍄") { coff = (coff * 0.7); } else if (emoji[rnd] == "🌕") { coff = (coff * 2); } else if (emoji[rnd] == "🌖") { coff = (coff * 1.25); } else if (emoji[rnd] == "🌒") { coff = (coff * 0.75); } else if (emoji[rnd] == "🌓") { coff = (coff * 1); } else if (emoji[rnd] == "💥") { coff = (coff * 1.75); } else if (emoji[rnd] == "🐞") { coff = coff * 1.3; } else if (emoji[rnd] == "🤡") { coff = coff / 1.5; } else if (emoji[rnd] == "🎢") { coff = (coff * 0.7); } else if (emoji[rnd] == "⚡️") { int lightning = RandomNumberGenerator.GetInt32(1, 31); coff = (coff * ((double)((double)lightning / (double)10))); } else if (emoji[rnd] == "🎱") { coff = coff * 2.5; } else if (emoji[rnd] == "💣") { coff = coff * 0.2; } else if (emoji[rnd] == "🐴") { coff = (coff * 0.8); } else if (emoji[rnd] == "🦆") { coff = (coff * 1.15); } else if (emoji[rnd] == "🐭") { coff = coff * 0.85; } else if (emoji[rnd] == "👻") { coff = Math.Pow(coff, 1.5); } else if (emoji[rnd] == "💊") { int capsule = RandomNumberGenerator.GetInt32(1, 3); if (capsule == 1) { coff = coff * 0; } else if (capsule == 2) { coff = coff * 2; } } var index = text.IndexOf("🎁"); text = text.Remove(index, 2).Insert(index, emoji[rnd]); if (i == 2) { text += $"\nВы выиграли: {(long)(bet * coff) - bet}"; Other.changeBalance(mess.From, (long)(bet * coff) - bet); } await Task.Delay(2000); await BotMain.bot.EditMessageTextAsync(bandit.Chat.Id, bandit.MessageId, text); } } catch (Exception e) { Other.OnReceivedError(e, mess, $"Произошла ошибка. Напишите \"/report текст проблемы\" в чат, чтобы дать разработчику узнать о проблеме."); } }
public static async void notifyFunc() { while (true) { await Task.Run(() => { try { for (int i = 0; i <= BotMain.osuUserTGs.Count - 1; i++) { osuApi osuApi = new osuApi(BotMain.osuToken); Score[] recentScores = osuApi.GetRecentScoresByNameAsync(BotMain.osuUserTGs[i].name, 100).Result; if (recentScores == null) { continue; } int start = recentScores.Length - 1; bool startgot = false; for (int q = recentScores.Length - 1; q >= 0; q--) { if (DateTimeOffset.Parse(recentScores[q].date) > BotMain.osuUserTGs[i].lastCheckedScore) { start = q; startgot = true; break; } } if (!startgot) { continue; } for (int j = start; j >= 0; j--) { double accuracy = (50 * double.Parse(recentScores[j].count50) + 100 * double.Parse(recentScores[j].count100) + 300 * double.Parse(recentScores[j].count300)) / (300 * (double.Parse(recentScores[j].countmiss) + double.Parse(recentScores[j].count50) + double.Parse(recentScores[j].count100) + double.Parse(recentScores[j].count300))) * 100; Beatmap beatmap = osuApi.GetBeatmapByBeatmapIdAsync(int.Parse(recentScores[j].beatmap_id)).Result; if (beatmap == null) { continue; } double curpp = Other.ppCalc(beatmap, accuracy, (Mods)osuApi.CalculateModsMods(int.Parse(recentScores[j].enabled_mods)), int.Parse(recentScores[j].countmiss), int.Parse(recentScores[j].maxcombo)); double ifFCpp = Other.ppCalc(beatmap, accuracy, (Mods)osuApi.CalculateModsMods(int.Parse(recentScores[j].enabled_mods)), 0, int.Parse(beatmap.max_combo)); Mods mods = (Mods)osuApi.CalculateModsMods(int.Parse(recentScores[j].enabled_mods)); if (curpp > 200 && recentScores[j].rank != "F") { foreach (var item in BotMain.groups) { if (item.notifyOsu) { BotMain.bot.SendTextMessageAsync(item.id, $"<b><u>{BotMain.osuUserTGs[i].name}</u></b> недавно прошел данную карту, набрав <i>{curpp:N0}pp</i>!\n" + $"<b>({recentScores[j].rank})</b> <a href=\"https://osu.ppy.sh/beatmaps/{beatmap.beatmap_id}\">{beatmap.title} [{beatmap.version}]</a> <b>{osuApi.GetBeatmapByBeatmapIdAsync(int.Parse(beatmap.beatmap_id)).Result.GetApproved()}</b>\n" + $"{recentScores[j].count300}-{recentScores[j].count100}-{recentScores[j].count50}-{recentScores[j].countmiss}x❌ - <b><i>{accuracy:N2}%</i></b>\n" + $"<b>{mods}</b> <i>{recentScores[j].maxcombo}/{beatmap.max_combo}</i> <b><u>{curpp:N0}pp</u></b> (<b><u>{ifFCpp:N0}pp</u></b> if FC)\n" + $"{DateTimeOffset.Parse(recentScores[j].date).AddHours(5):dd.MM.yyyy HH:mm}", ParseMode.Html, disableNotification: true).Wait(); } } } BotMain.osuUserTGs[i].lastCheckedScore = DateTimeOffset.Parse(recentScores[j].date); } } } catch (Exception ex) { Other.OnReceivedError(ex, null, ""); } }); } }