コード例 #1
0
ファイル: Events.cs プロジェクト: Lygaen/Proty
        public static Task MessageCreated(DiscordClient sender, MessageCreateEventArgs e)
        {
            Task.Run(async() =>
            {
                var cnext = sender.GetCommandsNext();
                var msg   = e.Message;

                // Check if message has valid prefix.
                var dbGuild = await Db.Instance.FetchDbGuildAsync(e.Guild);
                if (dbGuild == null)
                {
                    await e.Channel.SendMessageAsync(MessageUtils.BuildLoading("Adding your guild to the DB..."));
                    await Db.Instance.CreateDbGuild(new DbGuild()
                    {
                        GuildId = e.Guild.Id,
                        Prefix  = "!",
                        Premium = false
                    });
                    Logger.LogInformation($"Added guild \"{e.Guild.Name}\" ({e.Guild.Id}) to the DB !");
                    await e.Channel.SendMessageAsync(MessageUtils.BuildSuccess("Guild added to the DB !"));
                    dbGuild = await Db.Instance.FetchDbGuildAsync(e.Guild);
                }

                var cmdStart = msg.GetStringPrefixLength(dbGuild.Prefix);
                if (cmdStart == -1)
                {
                    return;
                }

                // Retrieve prefix.
                var prefix = msg.Content[..cmdStart];