Beispiel #1
0
        public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args, CancellationToken cancellationToken)
        {
            _chatProcessor = new ChatProcessor(context);
            var msg = context.Update.Message;

            var isAdmin = await _chatProcessor.IsAdminGroup();

            var tagVal   = args[0];
            var sendText = "Perintah Untag hanya untuk ngadmin.";

            if (isAdmin)
            {
                await _chatProcessor.SendAsync("Memeriksa..");

                var isExist = await _tagsService.IsExist(_chatProcessor.Message.Chat.Id, tagVal);

                if (isExist)
                {
                    ConsoleHelper.WriteLine($"Sedang menghapus tag {tagVal}");
                    var unTag = await _tagsService.DeleteTag(_chatProcessor.Message.Chat.Id, tagVal);

                    if (unTag)
                    {
                        sendText = $"Hapus tag {tagVal} berhasil";
                    }

                    await _chatProcessor.EditAsync(sendText);

                    return;
                }
                else
                {
                    sendText = $"Tag {tagVal} tidak di temukan";
                }
            }

            await _chatProcessor.SendAsync(sendText);
        }
Beispiel #2
0
        public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args,
                                               CancellationToken cancellationToken)
        {
            _chatProcessor = new ChatProcessor(context);
            var msg = context.Update.Message;

            _settingsService = new SettingsService(msg);

            if (msg.Chat.Type == ChatType.Private)
            {
                await _chatProcessor.SendAsync("Welcome hanya untuk grup saja");

                return;
            }

            var partsMsg = msg.Text.Split(' ').ToArray();

            string[] commands = { "message", "msg", "button", "btn" };
            ConsoleHelper.WriteLine(partsMsg.ToJson());

            var isAdmin = await _chatProcessor.IsAdminGroup();

            if (isAdmin)
            {
                if (msg.ReplyToMessage != null)
                {
                    var repMsg = msg.ReplyToMessage;
                    if (repMsg.GetFileId() != "")
                    {
                        var mediaType = repMsg.Type.ToString().ToLower();
                        await _chatProcessor.SendAsync("Sedang menyimpan Welcome Media..");

                        await _settingsService.UpdateCell("welcome_media", repMsg.GetFileId());

                        await _settingsService.UpdateCell("welcome_media_type", mediaType);

                        ConsoleHelper.WriteLine("Save media success..");

                        await _chatProcessor.EditAsync("Welcome Media berhasil di simpan.");

                        return;
                    }
                    else
                    {
                        await _chatProcessor.SendAsync("Media tidak terdeteksi di pesan yg di reply tersebut.");

                        return;
                    }
                }

                ConsoleHelper.WriteLine(partsMsg.Length);

                var missParamText = $"Parameter yg di dukung {string.Join(", ", commands)}" +
                                    $"\nContoh: <code>/setwelcome message</code>";

                if (partsMsg.Length > 1)
                {
                    if (commands.Contains(partsMsg[1]))
                    {
                        if (partsMsg[2] != null)
                        {
                            var target = partsMsg[1]
                                         .Replace("msg", "message")
                                         .Replace("btn", "button");
                            var columnTarget = $"welcome_{target}";
                            var data         = msg.Text
                                               .Replace(partsMsg[0], "")
                                               .Replace(partsMsg[1], "").Trim();

                            // ConsoleHelper.WriteLine(columnTarget);
                            // ConsoleHelper.WriteLine(data);

                            await _chatProcessor.SendAsync("Sedang menyimpan Welcome Message..");

                            await _settingsService.UpdateCell(columnTarget, data);

                            await _chatProcessor.EditAsync($"Welcome {target} berhasil di simpan!");
                        }
                        else
                        {
                            await _chatProcessor.SendAsync("Masukan Pesan atau tombol yang akan di tetapkan");
                        }
                    }
                    else
                    {
                        await _chatProcessor.SendAsync(missParamText);
                    }
                }
                else
                {
                    await _chatProcessor.SendAsync(missParamText);
                }
            }
        }
Beispiel #3
0
        public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args, CancellationToken cancellationToken)
        {
            _chatProcessor = new ChatProcessor(context);

            var kickTargets = new List <User>();

            var     msg    = context.Update.Message;
            Message repMsg = null;
            var     fromId = msg.From.Id;

            // var idTargets = new List<int>();

            kickTargets.Add(msg.From);

            if (msg.ReplyToMessage != null)
            {
                repMsg = msg.ReplyToMessage;
                // idTarget = repMsg.From.id;
                kickTargets.Add(repMsg.From);

                if (repMsg.NewChatMembers != null)
                {
                    kickTargets.Clear();
                    var userTargets = repMsg.NewChatMembers;
                    kickTargets.AddRange(userTargets);

                    // foreach (var target in userTargets)
                    // {
                    //     idTargets.Add(target.Id);
                    // }
                }
            }

            await _chatProcessor.DeleteAsync(msg.MessageId);

            var isAdmin = await _chatProcessor.IsAdminGroup();

            if (kickTargets[0].Id != msg.From.Id && isAdmin)
            {
                var isKicked = false;
                foreach (var target in kickTargets)
                {
                    var idTarget = target.Id;
                    var sendText = string.Empty;

                    // await _chatProcessor.AppendTextAsync($"Sedang menendang {idTarget}");
                    isKicked = await _chatProcessor.KickMemberAsync(target);

                    await _chatProcessor.UnbanMemberAsync(target);

                    if (isKicked)
                    {
                        sendText = $"{target} berhasil di tendank ";

                        sendText += idTarget == fromId ? $"oleh Self-kick" : $".";
                    }
                    else
                    {
                        sendText = $"Gagal menendang {idTarget}";
                    }

                    await _chatProcessor.AppendTextAsync(sendText);
                }

                if (isKicked)
                {
                    await _chatProcessor.AppendTextAsync($"Sebanyak {kickTargets.Count} berhasil di tendang.");
                }
                else
                {
                    await _chatProcessor.AppendTextAsync("Gagal menendang bbrp anggota");
                }
            }
            else if (kickTargets[0].Id == fromId)
            {
                var idTarget = kickTargets[0];
                var isKicked = false;
                // await _chatProcessor.AppendTextAsync($"Sedang menendang {idTarget}");
                isKicked = await _chatProcessor.KickMemberAsync(idTarget);

                if (isKicked)
                {
                    var sendText = $"{idTarget} berhasil di tendang ";
                    sendText += idTarget.Id == fromId ? $"oleh Self-kick" : $".";
                    await _chatProcessor.AppendTextAsync(sendText);
                }
                else
                {
                    var sendTexts = $"Tendang {idTarget} gagal.";
                    await _chatProcessor.SendAsync(sendTexts);
                }
            }
            else
            {
                await _chatProcessor.SendAsync("Hanya admin yang bisa mengeksekusi");
            }
        }