コード例 #1
0
ファイル: RaidModule.cs プロジェクト: WaterKH/RaidCoordinator
        public async Task ResetRaid()
        {
            using var context = new RaidContext(new DbContextOptions <RaidContext>());

            context.ChannelTokens.Remove(context.ChannelTokens.FirstOrDefault(x => BitConverter.ToUInt64(x.ChannelId) == Context.Channel.Id));

            context.SaveChanges();

            await ReplyAsync("Channel removed. Please use the !setraid command to set a new channel.");
        }
コード例 #2
0
        public async Task <Embed> SendChannelToken(ulong channelId, ulong guildId, bool resetToken = false)
        {
            try
            {
                //var manager = this.ChannelManagerPair[channelId];

                using var context = new RaidContext(DbContextOptions);

                ChannelToken channelTokenObject = null;
                foreach (var channelToken in context.ChannelTokens)
                {
                    if (BitConverter.ToUInt64(channelToken.ChannelId) == channelId)
                    {
                        channelTokenObject = channelToken;
                        break;
                    }
                }

                EmbedBuilder builder = new EmbedBuilder();

                builder.WithTitle("Raid Coordinating Credentials");

                var tokenInEmbed = 0;
                var infoInEmbed  = "";

                if (channelTokenObject == null)
                {
                    var token = this.Random.Next(256, Int32.MaxValue);

                    context.Add(new ChannelToken {
                        ChannelId = BitConverter.GetBytes(channelId), GuildId = BitConverter.GetBytes(guildId), Token = token
                    });

                    context.SaveChanges();

                    tokenInEmbed = token;
                    infoInEmbed  = "Use this **token** to authenticate with your **channel Id**.";
                }
                else
                {
                    if (resetToken)
                    {
                        channelTokenObject.Token = this.Random.Next(256, Int32.MaxValue);

                        context.SaveChanges();

                        infoInEmbed = "**TOKEN RESET**: Use this **token** to authenticate with your **channel Id**.";
                    }
                    else
                    {
                        infoInEmbed = "Please use the last **token** generated for your **channel Id**. If you would like a new token, use the **!resetraidtoken** command.";
                    }

                    tokenInEmbed = channelTokenObject.Token;
                }

                builder.AddField("Info:", infoInEmbed);
                builder.AddField("Channel Id:", channelId);
                builder.AddField("Token:", tokenInEmbed);

                return(builder.Build());
            }
            catch (Exception e)
            {
                logger.LogError(e.Message + e.StackTrace);
                throw;
            }
        }