예제 #1
0
 public DiscordUrieConfig(DiscordUrieSettings Settings, SQLiteConnection SQLConn, List <DiscordUrieGuild> Guilds = null, DiscordActivity Activity = null)
 {
     this.SettingsInstance = Settings;
     this.SQLConn          = SQLConn;
     this.GuildSettings    = Guilds;
     this.StartupActivity  = Activity;
 }
예제 #2
0
        public async Task MainAsync()
        {
            //Check for the database file and create it if it doesn't exist
            if (!File.Exists("DiscordUrieConfig.db"))
            {
                SQLiteConnection.CreateFile("DiscordUrieConfig.db");
            }
            if (!File.Exists("activity.json"))
            {
                File.Create("activity.json");
            }
            //Setup database connection
            var SQLConn = new SQLiteConnection("Data Source=DiscordUrieConfig.db;Version=3;");
            var Sett    = new DiscordUrieSettings();
            await Sett.Createdb(SQLConn);

            //Load settings from database and create a new instance of the bot with it
            var DiscordUrie = new DiscordUrie(await Sett.LoadSettings(SQLConn), SQLConn, Sett);
            //Start.
            await DiscordUrie.StartAsync();

            await Task.Delay(-1);
        }
예제 #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());
        }