Ignore commands on certain serves
This commit is contained in:
parent
ac43d087b1
commit
7a250f6642
2 changed files with 27 additions and 4 deletions
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -28,10 +29,12 @@ namespace Geekbot.net
|
|||
private readonly IUserRepository _userRepository;
|
||||
private readonly IReactionListener _reactionListener;
|
||||
private readonly DatabaseContext _messageCounterDatabaseContext;
|
||||
private readonly RestApplication _applicationInfo;
|
||||
private readonly List<ulong> _ignoredServers;
|
||||
|
||||
public Handlers(DatabaseInitializer databaseInitializer, IDiscordClient client, IGeekbotLogger logger, IAlmostRedis redis,
|
||||
IServiceProvider servicesProvider, CommandService commands, IUserRepository userRepository,
|
||||
IReactionListener reactionListener)
|
||||
IReactionListener reactionListener, RestApplication applicationInfo)
|
||||
{
|
||||
_database = databaseInitializer.Initialize();
|
||||
_messageCounterDatabaseContext = databaseInitializer.Initialize();
|
||||
|
@ -42,6 +45,14 @@ namespace Geekbot.net
|
|||
_commands = commands;
|
||||
_userRepository = userRepository;
|
||||
_reactionListener = reactionListener;
|
||||
_applicationInfo = applicationInfo;
|
||||
// ToDo: create a clean solution for this...
|
||||
_ignoredServers = new List<ulong>()
|
||||
{
|
||||
228623803201224704, // SwitzerLAN
|
||||
169844523181015040, // EEvent
|
||||
248531441548263425 // MYI
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -56,10 +67,21 @@ namespace Geekbot.net
|
|||
if (message.Author.IsBot) return Task.CompletedTask;
|
||||
var argPos = 0;
|
||||
|
||||
var guildId = ((SocketGuildChannel) message.Channel).Guild.Id;
|
||||
// Some guilds only wanted very specific functionally without any of the commands, a quick hack that solves that short term...
|
||||
// ToDo: cleanup
|
||||
if (_ignoredServers.Contains(guildId))
|
||||
{
|
||||
if (message.Author.Id != _applicationInfo.Owner.Id)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
var lowCaseMsg = message.ToString().ToLower();
|
||||
if (lowCaseMsg.StartsWith("hui"))
|
||||
{
|
||||
var hasPing = _database.GuildSettings.FirstOrDefault(guild => guild.GuildId.Equals(((SocketGuildChannel) message.Channel).Guild.Id.AsLong()))?.Hui ?? false;
|
||||
var hasPing = _database.GuildSettings.FirstOrDefault(guild => guild.GuildId.Equals(guildId.AsLong()))?.Hui ?? false;
|
||||
if (hasPing)
|
||||
{
|
||||
message.Channel.SendMessageAsync("hui!!!");
|
||||
|
@ -69,7 +91,7 @@ namespace Geekbot.net
|
|||
|
||||
if (lowCaseMsg.StartsWith("ping ") || lowCaseMsg.Equals("ping"))
|
||||
{
|
||||
var hasPing = _database.GuildSettings.FirstOrDefault(guild => guild.GuildId.Equals(((SocketGuildChannel) message.Channel).Guild.Id.AsLong()))?.Ping ?? false;
|
||||
var hasPing = _database.GuildSettings.FirstOrDefault(guild => guild.GuildId.Equals(guildId.AsLong()))?.Ping ?? false;
|
||||
if (hasPing)
|
||||
{
|
||||
message.Channel.SendMessageAsync("pong");
|
||||
|
|
|
@ -156,6 +156,7 @@ namespace Geekbot.net
|
|||
var isConneted = await IsConnected();
|
||||
if (isConneted)
|
||||
{
|
||||
var applicationInfo = await _client.GetApplicationInfoAsync();
|
||||
await _client.SetGameAsync(_globalSettings.GetKey("Game"));
|
||||
_logger.Information(LogSource.Geekbot, $"Now Connected as {_client.CurrentUser.Username} to {_client.Guilds.Count} Servers");
|
||||
|
||||
|
@ -170,7 +171,7 @@ namespace Geekbot.net
|
|||
_servicesProvider = _services.BuildServiceProvider();
|
||||
await _commands.AddModulesAsync(Assembly.GetEntryAssembly(), _servicesProvider);
|
||||
|
||||
var handlers = new Handlers(_databaseInitializer, _client, _logger, _redis, _servicesProvider, _commands, _userRepository, reactionListener);
|
||||
var handlers = new Handlers(_databaseInitializer, _client, _logger, _redis, _servicesProvider, _commands, _userRepository, reactionListener, applicationInfo);
|
||||
|
||||
_client.MessageReceived += handlers.RunCommand;
|
||||
_client.MessageDeleted += handlers.MessageDeleted;
|
||||
|
|
Loading…
Reference in a new issue