Example #1
0
        public async Task <DiscordUrieConfig> CreateAllDefaultSettings(BaseDiscordClient client, SQLiteConnection SQLConn)
        {
            DiscordUrieConfig OutputConfig = new DiscordUrieConfig(this, SQLConn)
            {
                StartupActivity = new DiscordActivity("the voices in my head", ActivityType.ListeningTo),

                GuildSettings = await CreateGuildDefaultSettings(client.Guilds.Values)
            };

            return(OutputConfig);
        }
Example #2
0
        public async Task <DiscordUrieConfig> LoadSettings(SQLiteConnection conn)
        {
            await conn.OpenAsync();

            JsonSerializerSettings serializerSettings = new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore
            };

            var command = new SQLiteCommand("SELECT * FROM config", conn);
            var reader  = await command.ExecuteReaderAsync();

            DiscordUrieConfig OutSettings = new DiscordUrieConfig(this, conn)
            {
                StartupActivity = JsonConvert.DeserializeObject <DiscordActivity>(File.ReadAllText("activity.json")),
                GuildSettings   = new List <DiscordUrieGuild>()
            };

            while (await reader.ReadAsync())
            {
                OutSettings.GuildSettings.Add(new DiscordUrieGuild(Convert.ToUInt64(reader["id"]))
                {
                    ColorEnabled       = Convert.ToBoolean(reader["ColorEnabled"]),
                    ColorLocked        = Convert.ToBoolean(reader["ColorLocked"]),
                    ColorBlacklistMode = (BlackListModeEnum)Convert.ToInt32(reader["ColorBlacklistMode"]),
                    ColorBlacklist     = JsonConvert.DeserializeObject <List <ulong> >((string)reader["ColorBlacklist"]),
                    BansEnabled        = Convert.ToBoolean(reader["BansEnabled"]),
                    BannedIds          = JsonConvert.DeserializeObject <List <ulong> >((string)reader["BannedIds"]),
                    Tags = JsonConvert.DeserializeObject <List <DiscordUrieTag> >((string)reader["Tags"]),
                    NotificationChannel = Convert.ToUInt64(reader["NotificationChannel"]),
                    AutoRole            = Convert.ToUInt64(reader["AutoRole"])
                });
            }
            conn.Close();
            return(OutSettings);
        }
Example #3
0
        public DiscordUrie(DiscordUrieConfig cfg, SQLiteConnection connection, DiscordUrieSettings sett)
        {
            SettingsInstance    = sett;
            SQLConn             = connection;
            this.StartTime      = DateTime.Now;
            this.Config         = cfg;
            this.MusicData      = new List <GuildMusicData>();
            this.LockedOutUsers = new List <DiscordMember>();
            string token;

            //Check for a saved token
            if (!File.Exists("token.txt"))
            {
                Console.Write("Token file not found. Please input a Discord bot token: ");
                token = Console.ReadLine();

                File.WriteAllText("token.txt", token);
                Console.Clear();
            }
            else
            {
                token = File.ReadAllText("token.txt");
            }

            //Check for a saved LavaLink server password
            //Maybe I should consolidate this, the token and the scplist info to cleanup these files.
            if (!File.Exists("lavapass.txt"))
            {
                Console.Write("Input the lavalink server password: "******"lavapass.txt", this.LavaPass);
                Console.Clear();
            }
            else
            {
                this.LavaPass = File.ReadAllText("lavapass.txt");
            }

            //Check for saved ScpList info
            if (!File.Exists("ScpInfo.txt"))
            {
                Console.Write("Input your SCP account ID");
                this.SCPID = Convert.ToInt32(Console.ReadLine());
                Console.Write("Input your SCP server api key: ");
                this.SCPKey = Console.ReadLine();
                string[] data = { this.SCPID.ToString(), this.SCPKey };
                File.WriteAllLines("ScpInfo.txt", data);
            }
            else
            {
                var data = File.ReadAllLines("ScpInfo.txt");
                this.SCPID  = Convert.ToInt32(data[0]);
                this.SCPKey = data[1];
            }

            //Initial client setup
            this.Client = new DiscordClient(new DiscordConfiguration
            {
                Token           = token,
                MinimumLogLevel = LogLevel.Information,
                Intents         = DiscordIntents.All,
            });

            //Client events setup
            this.Client.Ready              += this.Client_Ready;
            this.Client.ClientErrored      += this.ErrorHandler;
            this.Client.GuildMemberRemoved += this.UserLeaveGuild;
            this.Client.GuildMemberAdded   += this.UserJoinGuild;
            this.Client.GuildAvailable     += this.GuildAvailable;
            this.Client.GuildDeleted       += this.GuildDeleted;
            this.Client.SocketOpened       += async(client, e) =>
            {
                await Task.Yield();

                this.SocketStart = DateTime.Now;
            };


            this.Client.MessageCreated += async(client, e) =>
            {
                if (!e.Author.IsBot)
                {
                    await this.ChatBansEventCall(e);
                }
            };

            //Build dependancies for injection
            var depend = new ServiceCollection()
                         .AddSingleton(this)
                         .BuildServiceProvider();

            //Final client setup
            this.CNext = Client.UseCommandsNext(new CommandsNextConfiguration
            {
                CaseSensitive     = false,
                StringPrefixes    = CmdPrefix,
                EnableDefaultHelp = true,
                EnableDms         = false,
                Services          = depend
            });

            this.Lavalink = Client.UseLavalink();
            this.CNext.RegisterCommands(Assembly.GetExecutingAssembly());
            this.Interactivity = Client.UseInteractivity(new InteractivityConfiguration());
        }