Example #1
0
        public BotManagment(DiscordRepository discordRepository)
        {
            bool anyDiscordBotCreated = false;

            // Any existing Bots in Database?
            using (DiscordContext discordContext = discordRepository.GetDiscordContext())
            {
                anyDiscordBotCreated = discordContext.DiscordBots.Any();
            }

            // Currently no existing DiscordBot -> Ask to create one
            if (!anyDiscordBotCreated)
            {
                ConsoleOutput.WriteLine(ConsoleType.Debug,
                                        "Currently no existing DiscordBot. Enter custom Token or default used? (Y/N)");
                string botToken = "MzE1MTkxNDI0NDgyMDE3Mjgx.DMTmbA.mj6lvnSnk1JJkxIDNgO4RMOe2m4";
                if (Console.ReadLine()?.ToLower() == "y")
                {
                    ConsoleOutput.WriteLine(ConsoleType.Config, "Please enter the Bot Token:");

                    // read and check bot token
                    botToken = Console.ReadLine();
                }

                if (botToken != null)
                {
                    // Create bot and save to database
                    DiscordBot discordBot = new DiscordBot
                    {
                        Token = botToken
                    };
                    using (DiscordContext discordContext = discordRepository.GetDiscordContext())
                    {
                        discordContext.DiscordBots.Add(discordBot);
                        discordContext.SaveChanges();
                    }

                    anyDiscordBotCreated = true;
                }
            }

            // Discord Bots found -> Start them all
            if (anyDiscordBotCreated)
            {
                using (DiscordContext discordContext = discordRepository.GetDiscordContext())
                {
                    foreach (DiscordBot discordBot in discordContext.DiscordBots)
                    {
                        DiscordClient newDiscordClient = Initialization.Setup(discordBot);
                        Initialization.Connect(newDiscordClient);
                        Initialization.BindEvents(newDiscordClient);
                    }
                }
            }
        }
Example #2
0
        public DiscordHandler(API api, IEventHandler eventHandler)
        {
            DiscordRepository = DiscordRepository.GetInstance();
            DiscordEvents.GetInstance();
            BotManagment = new BotManagment.BotManagment(DiscordRepository);

            // Debug
            DiscordEvents.OnChannelMessage += (channel, author, message) =>
            {
                ConsoleOutput.WriteLine(ConsoleType.Debug,
                                        $"{channel.ChannelName} -> {author.Username}: ${message}");
            };
        }
Example #3
0
 private ChannelManagment()
 {
     _discordRepository = DiscordRepository.GetInstance();
 }
Example #4
0
 public static DiscordRepository GetInstance()
 {
     return(_discordRepository ?? (_discordRepository = new DiscordRepository()));
 }