コード例 #1
0
ファイル: Program.cs プロジェクト: zH4x/Unreal-Dumping-Agent
        private async Task DiscordManager_MessageHandler(SocketUserMessage message, SocketCommandContext context)
        {
            // Update users
            var curUser = Utils.KnownUsers.FirstOrDefault(u => u.ID == context.User.Id);

            if (curUser == null)
            {
                Utils.KnownUsers.Add(new UsersInfo {
                    ID = context.User.Id
                });
                curUser = Utils.KnownUsers.First(u => u.ID == context.User.Id);
            }

            // message not form DM
            int argPos = 0;

            if (!context.IsPrivate &&
                message.HasStringPrefix("!agent ", ref argPos) ||
                message.HasMentionPrefix(Utils.DiscordManager.CurrentBot, ref argPos))
            {
                var result = await Utils.DiscordManager.ExecuteAsync(context, argPos);

                if (!result.IsSuccess)
                {
                    Utils.ConsoleText("Commands", $"Can't executing a command. Text: {context.Message.Content} | Error: {result.ErrorReason}", ConsoleColor.Red);
                }
            }

            // message from DM
            var uTask = await Utils.ChatManager.PredictQuestion(context.Message.Content);

            if (uTask.TypeEnum() == EQuestionType.None)
            {
                await context.User.SendMessageAsync(DiscordText.GetRandomNotUnderstandString());

                return;
            }

            // if bot is public bot, not run on local pc
            if (Utils.BotWorkType == Utils.BotType.Public)
            {
                if (string.IsNullOrEmpty(curUser.IP))
                {
                    var bEmbed = new EmbedBuilder();
                    bEmbed.WithColor(Color.DarkOrange);
                    bEmbed.WithTitle($"Linking");
                    bEmbed.WithDescription($"I should link with your local `Unreal Dumping Agent`.\n" +
                                           $"That's mean i will get your `IP` (it's safe i will not `Attack` u {DiscordText.GetRandomHappyEmoji()}).\n" +
                                           $"So open the blow `link` and let me play {DiscordText.GetRandomHappyEmoji()}.");
                    bEmbed.AddField($"Linking Link", $"http://localhost:2911");
                    bEmbed.WithUrl(Utils.DonateUrl);
                    bEmbed.WithFooter(Utils.DiscordFooterText, Utils.DiscordFooterImg);

                    await context.User.SendMessageAsync(embed : bEmbed.Build());

                    return;
                }

                // create function to process text through http
                return;
            }

            /* COMMANDS START HERE */
            if (Utils.IsDebug())
            {
                await context.User.SendMessageAsync($"ok, that's what i think you need to do:\n`{uTask.TypeEnum():G}` => `{uTask.TaskEnum():G}`\n--------------------------");
            }

            // Don't Wait
            #pragma warning disable 4014
            ExecuteTasks(curUser, uTask, message, context);
            #pragma warning restore 4014
        }
コード例 #2
0
 public async Task AddMe()
 {
     await Context.User.SendMessageAsync("Hi noob. " + DiscordText.GetRandomHappyEmoji());
 }