Esempio n. 1
0
        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.");
        }
Esempio n. 2
0
        // Todo Add a custom emote option
        public RaidCoordinatorService(IServiceProvider serviceProvider, DbContextOptions <RaidContext> dbContextOptions, ILogger <RaidCoordinatorService> logger)
        {
            this.ServiceProvider  = serviceProvider;
            this.DbContextOptions = dbContextOptions;
            this.logger           = logger;

            this.ServiceProvider.GetRequiredService <DiscordService>().client.ReactionAdded    += OnReactionChanged;
            this.ServiceProvider.GetRequiredService <DiscordService>().client.ReactionRemoved  += OnReactionChanged;
            this.ServiceProvider.GetRequiredService <DiscordService>().client.ReactionsCleared += OnReactionsCleared;
            //this.ServiceProvider.GetRequiredService<DiscordService>().client.MessageReceived += OnMessageReceived;

            this.logger.LogInformation("Func addition complete");

            using var context = new RaidContext(DbContextOptions);

            foreach (var channelToken in context.ChannelTokens)
            {
                this.ChannelManagerPair.Add(BitConverter.ToUInt64(channelToken.ChannelId), new RaidManager());
            }
        }
Esempio n. 3
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;
            }
        }