internal async Task ConnectAsync(DiscordBotConfig config)
        {
            Log.Information("Initializing connection.");
            _commandHandler    = new CommandHandlerService(_client, _logger, config, _service, _serviceProvider);
            _messageHandler    = new MessageHandlerService(_client, _logger, config, _levelingService, _userAccountRepository);
            _userEventsHandler = new UserEventsHandlerService(_client, _logger, config, _userAccountRepository);
            _client.Log       += _logger.Log;
            _client.Ready     += ReadyAsync;
            if (config.Token == null || config.Token == "")
            {
                throw new ArgumentNullException("Token", "Discord Bot Token is empty!");
            }
            if (config.CmdPrefix == null || config.CmdPrefix == "")
            {
                throw new ArgumentNullException("cmdPrefix", "Discord Bot cmdPrefix is empty!");
            }

            await _client.LoginAsync(TokenType.Bot, config.Token);

            await _client.StartAsync();

            await _commandHandler.InitializeAsync();

            _messageHandler.Initialize();
            _userEventsHandler.Initialize();
            await Task.Delay(-1);
        }
Beispiel #2
0
 public UserEventsHandlerService(DiscordSocketClient client, DiscordLogger logger, DiscordBotConfig config, IUserAccountRepository userAccountRepository)
 {
     _userAccountRepository = userAccountRepository;
     _config = config;
     _client = client;
     _logger = logger;
 }
Beispiel #3
0
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            _logger.LogInformation("Initializing");
            var bots = new List <IBot>();

            if (cancellationToken.CanBeCanceled)
            {
                cancellationToken.Register(() => _cancellationTokenSource.Cancel());
            }

            if (!_configuration.GetSection("Discord").Exists())
            {
                _logger.LogCritical("Missing configuration for Discord features");
            }

            _logger.LogDebug("Initializing bot logic for Discord");
            var discordConfig = new DiscordBotConfig();

            _configuration.GetSection("Discord").Bind(discordConfig);
            var discordBot = new DiscordBot(_loggerFactory, new DiscordSocketClient(), discordConfig);

            bots.Add(discordBot);

            _logger.LogInformation("Starting {0} bots", bots.Count);
            bots.ForEach(t => t.RunAsync(_cancellationTokenSource.Token));
            await Task.Delay(-1, _cancellationTokenSource.Token);
        }
Beispiel #4
0
 public BotConfigRepository(DiscordLogger logger, IDataStorage dataStorage, DiscordBotConfig config)
 {
     _logger      = logger;
     _dataStorage = dataStorage;
     _config      = config;
     LoadOrCreate();
 }
Beispiel #5
0
 public CommandHandlerService(DiscordSocketClient client, DiscordLogger logger, DiscordBotConfig config, CommandService service, IServiceProvider serviceProvider)
 {
     _config          = config;
     _client          = client;
     _logger          = logger;
     _service         = service;
     _serviceProvider = serviceProvider;
 }
Beispiel #6
0
 public MeetingEventListener(
     ILogger <Discostor> logger,
     AutomuteService automuteService,
     ConfigRoot config)
 {
     _logger          = logger;
     _automuteService = automuteService;
     _config          = config.Discord;
 }
Beispiel #7
0
 public AutomuteService(
     ILogger <Discostor> logger,
     ConfigRoot config,
     EmoteManager emoteManager)
 {
     _logger       = logger;
     _config       = config.Discord;
     _emoteManager = emoteManager;
 }
        internal DiscordBot(DiscordBotConfig config)
        {
            this.Config = config;

            this.CommandService = new CommandService();

            this.Client = new DiscordSocketClient();
            this.Client.MessageReceived += this.HandleIncomingMessage;
        }
Beispiel #9
0
 public UnlinkCommand(
     ILogger <Discostor> logger,
     ConfigRoot config,
     AutomuteService automuteService)
 {
     _logger          = logger;
     _config          = config.Discord;
     _automuteService = automuteService;
 }
 public MessageHandlerService(DiscordSocketClient client, DiscordLogger logger, DiscordBotConfig config, LevelingService levelingService, IUserAccountRepository userRepo)
 {
     _config          = config;
     _client          = client;
     _logger          = logger;
     _levelingService = levelingService;
     _userRepo        = userRepo;
     _messagesList    = new List <Message>();
 }
Beispiel #11
0
 public HelpEmbedBuilder(
     CommandService comms,
     ILogger <Discostor> logger,
     ConfigRoot config
     )
 {
     _comms  = comms;
     _logger = logger;
     _config = config.Discord;
 }
Beispiel #12
0
        internal async Task ConnectAsync(DiscordBotConfig config)
        {
            _client.Log += _logger.Log;

            await _client.LoginAsync(TokenType.Bot, config.Token);

            await _client.StartAsync();

            await Task.Delay(-1);
        }
Beispiel #13
0
        private static void Main()
        {
            Unity.RegisterTypes();
            Console.WriteLine("Hello, Discord!");

            var discordBotConfig = new DiscordBotConfig
            {
                Token        = "ABC",
                SocketConfig = SocketConfig.GetDefault()
            };
        }
        public DiscordBotSettingsWindow(DiscordBotConfig config)
        {
            this.config = config;

            InitializeComponent();
            UpdateAmbientColors();

            TextBoxX_BotToken.Text = config.DiscordBotToken;
            TextBoxX_AppName.Text  = config.DefaultAppName;
            TextBoxX_Msg.Text      = config.DefaultUpdateMessage;
        }
Beispiel #15
0
 public NewGameCommand(
     ILogger <Discostor> logger,
     ConfigRoot config,
     IGameManager gameManager,
     AutomuteService automuteService)
 {
     _logger          = logger;
     _config          = config.Discord;
     _gameManager     = gameManager;
     _automuteService = automuteService;
 }
Beispiel #16
0
 public HelpCommand(
     ILogger <Discostor> logger,
     ConfigRoot config,
     CommandService comms,
     HelpEmbedBuilder builder)
 {
     _logger  = logger;
     _config  = config.Discord;
     _comms   = comms;
     _builder = builder;
 }
Beispiel #17
0
        public void LoadOrCreate()
        {
            _logger.Log($"Reading the configuration ({Constants.DISCORD_CONFIG_PATH})");
            var discordBotConfig = _dataStorage.RestoreObject <DiscordBotConfig>(Constants.DISCORD_CONFIG_PATH);

            if (discordBotConfig == null)
            {
                discordBotConfig = new DiscordBotConfig();
                _dataStorage.StoreObject(discordBotConfig, Constants.DISCORD_CONFIG_PATH);
            }
            _config = discordBotConfig;
        }
Beispiel #18
0
 public RefreshCommand(
     ILogger <Discostor> logger,
     ConfigRoot config,
     CommandService comms,
     IGameManager gameManager,
     AutomuteService automuteService)
 {
     _logger          = logger;
     _config          = config.Discord;
     _comms           = comms;
     _gameManager     = gameManager;
     _automuteService = automuteService;
 }
Beispiel #19
0
 /// <summary>
 /// Loads stored configuration settings for the Discord bot. Creates a new one if none found.
 /// </summary>
 internal void LoadStoredBotConfig()
 {
     try
     {
         DiscordBotConfig = _storage.Get <DiscordBotConfig>(BotConfigKey);
         Logger.Log("[Configuration] Loaded botConfig.json.");
     }
     catch (DataStorageKeyDoesNotExistException)
     {
         Logger.Log("[Configuration] No botConfig.json found. Defaulting to a new config.");
         DiscordBotConfig = new DiscordBotConfig();
         StoreCurrentBotConfig();
     }
 }
Beispiel #20
0
 public Bot(DiscordSocketClient mainClient,
            CommandService comms,
            IServiceProvider services,
            ConfigRoot config,
            ILogger <Discostor> logger,
            AutomuteService automuteService)
 {
     _mainClient      = mainClient;
     _comms           = comms;
     _services        = services;
     _config          = config.Discord;
     _logger          = logger;
     _automuteService = automuteService;
 }
Beispiel #21
0
        //


        static void Main(string[] args)
        {
            DiscordUnity.RegisterTypes();
            Console.WriteLine("Hello Discord!");

            //
            var discordBotConfig = new DiscordBotConfig
            {
                Token        = "ABC",
                SocketConfig = SocketConfig.GetDefault()
            };

            var connection = DiscordUnity.Resolve <Connection>();

            Console.ReadKey();
        }
Beispiel #22
0
        internal MuteController(
            ILogger <Discostor> logger,
            IGame game,
            SocketGuildUser user,
            DiscordBotConfig config,
            EmoteManager emoteManager)
        {
            _logger       = logger;
            _game         = game;
            _config       = config;
            _emoteManager = emoteManager;
            VoiceChannel  = user.VoiceChannel;

            _phase = PhaseTypes.Unknown;
            if (game.GameState != GameStates.Started)
            {
                _phase = PhaseTypes.Lobby;
            }

            // add players
            using (_logger.BeginScope("players"))
            {
                _logger.LogDebug($"Game \"{game.Code.Code}\" players:");
                foreach (var player in _game.Players)
                {
                    _players[player.Client.Id] = player;
                    _isDead[player.Client.Id]  = player.Character.PlayerInfo.IsDead;
                    _logger.LogDebug($"  {player.Character.PlayerInfo.PlayerName}");
                }
            }
            // add vc members
            using (_logger.BeginScope("vc-members"))
            {
                _logger.LogDebug($"VC \"{VoiceChannel.Name}\" members:");

                foreach (var vcuser in user.VoiceChannel.Users)
                {
                    _guildMembersInVC[vcuser.Id] = vcuser;
                    _defaultVCProps[vcuser.Id]   = CreateCurrentMuteState(vcuser);
                    _logger.LogDebug($"  {vcuser.Username}");
                }
            }
            _logger.LogDebug($"MuteController created.");
        }
        private static async Task Main(string[] args)
        {
            DiscordBotConfig config = JsonConvert.DeserializeObject <DiscordBotConfig>(File.ReadAllText("settings.json"));

            DatabaseConnection.Init(config);
            RedisConnection.Init(config);

            CampaignManager campaignManager = new();

            Task.WaitAll(campaignManager.LoadCampaignTimesAsync(), campaignManager.LoadPrizesAsync());

            DiscordBot bot = new(config);

            await bot.LoadCommandsAsync();

            await bot.SetupDiscordBot();

            Console.WriteLine("Ready!");

            await Task.Delay(-1);
        }
Beispiel #24
0
 public DiscordBotClient(DiscordBotConfig config)
 {
     this.config = config;
 }