Exemple #1
0
        private void Start(string[] args)
        {
            Console.Title = "Bot Ross - Admin Pannel";

#if PRIVATE
            PrivateModules.Install(_client);
#endif

            if (File.Exists("Ascii.txt"))
            {
                string ascii = File.ReadAllText("Ascii.txt");
                Console.WriteLine(ascii);
            }
            _client = new DiscordClient();

            Console.ForegroundColor = ConsoleColor.Green;

            _client.Log.Message += (s, e) => Console.WriteLine($"[{e.Severity}] {e.Source}: {e.Message}");

            _client.MessageReceived += _client_MessageReceived;

            _client.ExecuteAndWait(async() =>
            {
                while (true)
                {
                    try
                    {
                        await _client.Connect("00000000000000000"); //replace with your own
                        break;
                    }
                    catch (Exception ex)
                    {
                        _client.Log.Error($"Couldn't log in", ex);
                        await Task.Delay(_client.Config.FailedReconnectDelay);
                    }
                }
            });

            Console.ResetColor();
        }
Exemple #2
0
        private void Start(string[] args)
        {
#if !DNXCORE50
            Console.Title = $"{AppName} (Discord.Net v{DiscordConfig.LibVersion})";
#endif

            GlobalSettings.Load();

            _client = new DiscordClient(x =>
            {
                x.AppName               = AppName;
                x.AppUrl                = AppUrl;
                x.MessageCacheSize      = 0;
                x.UsePermissionsCache   = true;
                x.EnablePreUpdateEvents = true;
                x.LogLevel              = LogSeverity.Info;
                x.LogHandler            = OnLogMessage;
            })
                      .UsingCommands(x =>
            {
                x.AllowMentionPrefix = true;
                x.HelpMode           = HelpMode.Public;
                x.ExecuteHandler     = OnCommandExecuted;
                x.ErrorHandler       = OnCommandError;
            })
                      .UsingModules()
                      .UsingAudio(x =>
            {
                x.Mode = AudioMode.Outgoing;
                //x.EnableMultiserver = true;
                x.EnableEncryption = true;
                x.Bitrate          = AudioServiceConfig.MaxBitrate;
                x.BufferLength     = 10000;
            })
                      .UsingPermissionLevels(PermissionResolver);

            _client.AddService <SettingsService>();
            _client.AddService <HttpService>();

            // Modules module
            _client.AddModule <ModulesModule>("Modules", ModuleFilter.None);

            // Core custom modules
            _client.AddModule <BorderModule>("Border", ModuleFilter.None);
            _client.AddModule <RandomModule>("Random", ModuleFilter.None);
            _client.AddModule <TimerModule>("Timer", ModuleFilter.None);
            _client.AddModule <StarlightStageModule>("StarlightStage", ModuleFilter.None);

            // DiscordBot built-in modules
            _client.AddModule <AdminModule>("Admin", ModuleFilter.ServerWhitelist);
            _client.AddModule <ColorsModule>("Colors", ModuleFilter.ServerWhitelist);
            _client.AddModule <FeedModule>("Feeds", ModuleFilter.ServerWhitelist);
            _client.AddModule <GithubModule>("Repos", ModuleFilter.ServerWhitelist);
            _client.AddModule <PublicModule>("Public", ModuleFilter.None);
            _client.AddModule <TwitchModule>("Twitch", ModuleFilter.ServerWhitelist);
            _client.AddModule <StatusModule>("Status", ModuleFilter.ServerWhitelist);

            // Misc custom modules
            _client.AddModule <FinanceModule>("Finance", ModuleFilter.ServerWhitelist);
            _client.AddModule <GifModule>("Gif", ModuleFilter.None);
            _client.AddModule <N_desModule>("N_des", ModuleFilter.None);

            //_client.AddModule(new ExecuteModule(env, exporter), "Execute", ModuleFilter.ServerWhitelist);

#if PRIVATE
            PrivateModules.Install(_client);
#endif

            //Convert this method to an async function and connect to the server
            //DiscordClient will automatically reconnect once we've established a connection, until then we loop on our end
            //Note: ExecuteAndWait is only needed for Console projects as Main can't be declared as async. UI/Web applications should *not* use this function.
            _client.ExecuteAndWait(async() =>
            {
                while (true)
                {
                    try
                    {
                        await _client.Connect(GlobalSettings.Discord.Email, GlobalSettings.Discord.Password);
                        //_client.SetGame("debugging, sorry!");
                        //_client.SetGame("good to go~");
                        //await _client.ClientAPI.Send(new Discord.API.Client.Rest.HealthRequest());
                        break;
                    }
                    catch (Exception ex)
                    {
                        _client.Log.Error($"Login Failed", ex);
                        await Task.Delay(_client.Config.FailedReconnectDelay);
                    }
                }
            });
        }
Exemple #3
0
        private void Start(string[] args)
        {
            GlobalSettings.Load();

            //Set up the base client itself with no voice and small message queues
            _client = new DiscordClient(new DiscordConfig
            {
                AppName             = "VoltBot",
                AppUrl              = "https://github.com/RogueException/DiscordBot",
                AppVersion          = DiscordConfig.LibVersion,
                LogLevel            = LogSeverity.Info,
                MessageCacheSize    = 0,
                UsePermissionsCache = false
            })

                      //** Core Services **//
                      //These are services adding functionality from other Discord.Net.XXX packages

                      //Enable commands on this bot and activate the built-in help command
                      .UsingCommands(new CommandServiceConfig
            {
                CommandChar = '~',
                HelpMode    = HelpMode.Public
            })

                      //Enable command modules
                      .UsingModules()

                      //Enable audio support
                      .UsingAudio(new AudioServiceConfig
            {
                Mode = AudioMode.Outgoing,
                EnableMultiserver = false,
                EnableEncryption  = true,
                Bitrate           = 512,
                BufferLength      = 10000
            })

                      //** Command Permission Services **//
                      // These allow you to use permission checks on commands or command groups, or apply a permission globally (such as a blacklist)

                      //Add a blacklist service so we can add people that can't run any commands. We have used a whitelist instead to restrict it to just us.
                      .UsingGlobalBlacklist()
                      //.EnableGlobalWhitelist(GlobalSettings.Users.DevId))

                      //Assign users to our own role system based on their permissions in the server/channel a command is run in.
                      .UsingPermissionLevels((u, c) =>
            {
                if (u.Id == GlobalSettings.Users.DevId)
                {
                    return((int)PermissionLevel.BotOwner);
                }
                if (u.Server != null)
                {
                    if (u == c.Server.Owner)
                    {
                        return((int)PermissionLevel.ServerOwner);
                    }

                    var serverPerms = u.ServerPermissions;
                    if (serverPerms.ManageRoles)
                    {
                        return((int)PermissionLevel.ServerAdmin);
                    }
                    if (serverPerms.ManageMessages && serverPerms.KickMembers && serverPerms.BanMembers)
                    {
                        return((int)PermissionLevel.ServerModerator);
                    }

                    var channelPerms = u.GetPermissions(c);
                    if (channelPerms.ManagePermissions)
                    {
                        return((int)PermissionLevel.ChannelAdmin);
                    }
                    if (channelPerms.ManageMessages)
                    {
                        return((int)PermissionLevel.ChannelModerator);
                    }
                }
                return((int)PermissionLevel.User);
            })

                      //** Helper Services**//
                      //These are used by the modules below, and will likely be removed in the future

                      .AddService <SettingsService>()
                      .AddService <HttpService>()

                      //** Command Modules **//
                      //Modules allow for events such as commands run or user joins to be filtered to certain servers/channels, as well as provide a grouping mechanism for commands

                      .AddModule <AdminModule>("Admin", ModuleFilter.ServerWhitelist)
                      .AddModule <ColorsModule>("Colors", ModuleFilter.ServerWhitelist)
                      .AddModule <FeedModule>("Feeds", ModuleFilter.ServerWhitelist)
                      .AddModule <GithubModule>("Repos", ModuleFilter.ServerWhitelist)
                      .AddModule <ModulesModule>("Modules", ModuleFilter.None)
                      .AddModule <PublicModule>("Public", ModuleFilter.None)
                      .AddModule <TwitchModule>("Twitch", ModuleFilter.ServerWhitelist);
            //.AddModule(new ExecuteModule(env, exporter), "Execute", ModuleFilter.ServerWhitelist);

            //** Events **//

            _client.Log.Message += (s, e) => WriteLog(e);

            //Display errors that occur when a user tries to run a command
            //(In this case, we hide argcount, parsing and unknown command errors to reduce spam in servers with multiple bots)
            _client.Commands().CommandErrored += (s, e) =>
            {
                string msg = e.Exception?.GetBaseException().Message;
                if (msg == null) //No exception - show a generic message
                {
                    switch (e.ErrorType)
                    {
                    case CommandErrorType.Exception:
                        //msg = "Unknown error.";
                        break;

                    case CommandErrorType.BadPermissions:
                        msg = "You do not have permission to run this command.";
                        break;

                    case CommandErrorType.BadArgCount:
                        //msg = "You provided the incorrect number of arguments for this command.";
                        break;

                    case CommandErrorType.InvalidInput:
                        //msg = "Unable to parse your command, please check your input.";
                        break;

                    case CommandErrorType.UnknownCommand:
                        //msg = "Unknown command.";
                        break;
                    }
                }
                if (msg != null)
                {
                    _client.ReplyError(e, msg);
                    _client.Log.Error("Command", msg);
                }
            };

            //Log to the console whenever someone uses a command
            _client.Commands().CommandExecuted += (s, e) => _client.Log.Info("Command", $"{e.Command.Text} ({e.User.Name})");

            //Used to load private modules outside of this repo
#if PRIVATE
            PrivateModules.Install(_client);
#endif

            //** Run **//

#if !DNXCORE50
            Console.Title = $"{_client.Config.AppName} v{_client.Config.AppVersion} (Discord.Net v{DiscordConfig.LibVersion})";
#endif

            //Convert this method to an async function and connect to the server
            //DiscordClient will automatically reconnect once we've established a connection, until then we loop on our end
            //Note: Run is only needed for Console projects as Main can't be declared as async. UI/Web applications should *not* use this function.
            _client.Run(async() =>
            {
                while (true)
                {
                    try
                    {
                        await _client.Connect(GlobalSettings.Discord.Email, GlobalSettings.Discord.Password);
                        _client.SetGame("Discord.Net");
                        break;
                    }
                    catch (Exception ex)
                    {
                        _client.Log.Error($"Login Failed", ex);
                        await Task.Delay(_client.Config.FailedReconnectDelay);
                    }
                }
            });
        }
Exemple #4
0
        private void Start(string[] args)
        {
#if !DNXCORE50
            Console.Title = $"{AppName} (Discord.Net v{DiscordConfig.LibVersion})";
#endif

            GlobalSettings.Load();

            _client = new DiscordClient(x =>
            {
                x.AppName               = AppName;
                x.AppUrl                = AppUrl;
                x.MessageCacheSize      = 0;
                x.UsePermissionsCache   = false;
                x.EnablePreUpdateEvents = true;
                x.LogLevel              = LogSeverity.Info;
                x.LogHandler            = OnLogMessage;
            })

                      .UsingCommands(x =>
            {
                x.PrefixChar         = '!';
                x.AllowMentionPrefix = false;
                x.HelpMode           = HelpMode.Public;
                x.ExecuteHandler     = OnCommandExecuted;

                x.ErrorHandler = OnCommandError;
            })

                      .UsingModules()
                      .UsingAudio(x =>
            {
                x.Mode = AudioMode.Outgoing;
                x.EnableMultiserver = true;
                x.EnableEncryption  = true;
                x.Bitrate           = AudioServiceConfig.MaxBitrate;
                x.BufferLength      = 10000;
            })
                      .UsingPermissionLevels(PermissionResolver)

                      .AddService <SettingsService>()
                      .AddService <HttpService>()

                      .AddModule <AdminModule>("Admin", ModuleFilter.ServerWhitelist)
                      .AddModule <ColorsModule>("Colors", ModuleFilter.ServerWhitelist)
                      //.AddModule<FeedModule>("Feeds", ModuleFilter.ServerWhitelist)
                      //.AddModule<GithubModule>("Repos", ModuleFilter.ServerWhitelist)
                      .AddModule <ModulesModule>("Modules", ModuleFilter.None)
                      .AddModule <PublicModule>("Public", ModuleFilter.None)
                      .AddModule <TwitchModule>("Twitch", ModuleFilter.None)
                      .AddModule <StatusModule>("Status", ModuleFilter.ServerWhitelist)
                      .AddModule <Music>("Music", ModuleFilter.ServerWhitelist)
                      .AddModule <DiscordBot.Modules.Sql.sql>("sql", ModuleFilter.None);

            PublicModule.loadgods();

            //.AddModule(new ExecuteModule(env, exporter), "Execute", ModuleFilter.ServerWhitelist);

#if PRIVATE
            PrivateModules.Install(_client);
#endif

            /* IAudioClient test = new IAudioClient();
             * test.*/
            //Convert this method to an async function and connect to the server
            //DiscordClient will automatically reconnect once we've established a connection, until then we loop on our end
            //Note: ExecuteAndWait is only needed for Console projects as Main can't be declared as async. UI/Web applications should *not* use this function.

            _client.UserJoined += async(s, e) =>
            {
                DiscordBot.Modules.Sql.sql sqll = new Modules.Sql.sql();
                string message = sqll.getsinglevalue("servers", "server = " + e.Server.Id, "welcome");
                if (message != "" && message != null && message.Length > 0)
                {
                    Channel pm = await _client.CreatePrivateChannel(e.User.Id);

                    await pm.SendMessage(message);
                }
            };

            _client.ExecuteAndWait(async() =>
            {
                while (true)
                {
                    try
                    {
                        await _client.Connect(GlobalSettings.Discord.Email, GlobalSettings.Discord.Password);
                        _client.SetGame("O Bot");
                        break;
                    }
                    catch (Exception ex)
                    {
                        _client.Log.Error($"Login Failed", ex);
                        await Task.Delay(_client.Config.FailedReconnectDelay);
                    }
                }
            });
        }