disable automatic failover
This commit is contained in:
parent
f46e1b6071
commit
68b6312635
1 changed files with 163 additions and 163 deletions
|
@ -1,163 +1,163 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.InteropServices.ComTypes;
|
using System.Runtime.InteropServices.ComTypes;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
using Geekbot.net.Lib;
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.IClients;
|
using Geekbot.net.Lib.IClients;
|
||||||
using Geekbot.net.Modules;
|
using Geekbot.net.Modules;
|
||||||
using StackExchange.Redis;
|
using StackExchange.Redis;
|
||||||
|
|
||||||
namespace Geekbot.net
|
namespace Geekbot.net
|
||||||
{
|
{
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
private CommandService commands;
|
private CommandService commands;
|
||||||
private DiscordSocketClient client;
|
private DiscordSocketClient client;
|
||||||
private DependencyMap map;
|
private DependencyMap map;
|
||||||
private IRedisClient redis;
|
private IRedisClient redis;
|
||||||
private RedisValue token;
|
private RedisValue token;
|
||||||
|
|
||||||
private static void Main(string[] args)
|
private static void Main(string[] args)
|
||||||
{
|
{
|
||||||
Console.WriteLine(@" ____ _____ _____ _ ______ ___ _____");
|
Console.WriteLine(@" ____ _____ _____ _ ______ ___ _____");
|
||||||
Console.WriteLine(@" / ___| ____| ____| |/ / __ ) / _ \\_ _|");
|
Console.WriteLine(@" / ___| ____| ____| |/ / __ ) / _ \\_ _|");
|
||||||
Console.WriteLine(@"| | _| _| | _| | ' /| _ \| | | || |");
|
Console.WriteLine(@"| | _| _| | _| | ' /| _ \| | | || |");
|
||||||
Console.WriteLine(@"| |_| | |___| |___| . \| |_) | |_| || |");
|
Console.WriteLine(@"| |_| | |___| |___| . \| |_) | |_| || |");
|
||||||
Console.WriteLine(@" \____|_____|_____|_|\_\____/ \___/ |_|");
|
Console.WriteLine(@" \____|_____|_____|_|\_\____/ \___/ |_|");
|
||||||
Console.WriteLine("=========================================");
|
Console.WriteLine("=========================================");
|
||||||
Console.WriteLine("Starting...");
|
Console.WriteLine("Starting...");
|
||||||
|
|
||||||
Task.WaitAll(new Program().MainAsync());
|
Task.WaitAll(new Program().MainAsync());
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task MainAsync()
|
public async Task MainAsync()
|
||||||
{
|
{
|
||||||
client = new DiscordSocketClient();
|
client = new DiscordSocketClient();
|
||||||
commands = new CommandService();
|
commands = new CommandService();
|
||||||
redis = new RedisClient();
|
redis = new RedisClient();
|
||||||
|
|
||||||
token = redis.Client.StringGet("discordToken");
|
token = redis.Client.StringGet("discordToken");
|
||||||
if (token.IsNullOrEmpty)
|
if (token.IsNullOrEmpty)
|
||||||
{
|
{
|
||||||
Console.Write("Your bot Token: ");
|
Console.Write("Your bot Token: ");
|
||||||
var newToken = Console.ReadLine();
|
var newToken = Console.ReadLine();
|
||||||
redis.Client.StringSet("discordToken", newToken);
|
redis.Client.StringSet("discordToken", newToken);
|
||||||
token = newToken;
|
token = newToken;
|
||||||
|
|
||||||
Console.Write("Bot Owner User ID: ");
|
Console.Write("Bot Owner User ID: ");
|
||||||
var ownerId = Console.ReadLine();
|
var ownerId = Console.ReadLine();
|
||||||
redis.Client.StringSet("botOwner", ownerId);
|
redis.Client.StringSet("botOwner", ownerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
map = new DependencyMap();
|
map = new DependencyMap();
|
||||||
map.Add<ICatClient>(new CatClient());
|
map.Add<ICatClient>(new CatClient());
|
||||||
map.Add(redis);
|
map.Add(redis);
|
||||||
map.Add<IRandomClient>(new RandomClient());
|
map.Add<IRandomClient>(new RandomClient());
|
||||||
|
|
||||||
Console.WriteLine("Connecting to Discord...");
|
Console.WriteLine("Connecting to Discord...");
|
||||||
|
|
||||||
await Login();
|
await Login();
|
||||||
|
|
||||||
await Task.Delay(-1);
|
await Task.Delay(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Login()
|
public async Task Login()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await client.LoginAsync(TokenType.Bot, token);
|
await client.LoginAsync(TokenType.Bot, token);
|
||||||
await client.StartAsync();
|
await client.StartAsync();
|
||||||
client.Connected += FinishStartup;
|
client.Connected += FinishStartup;
|
||||||
}
|
}
|
||||||
catch (AggregateException)
|
catch (AggregateException)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Could not connect to discord...");
|
Console.WriteLine("Could not connect to discord...");
|
||||||
Environment.Exit(1);
|
Environment.Exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Reconnect(Exception exception)
|
public async Task Reconnect(Exception exception)
|
||||||
{
|
{
|
||||||
Console.WriteLine("=========================================");
|
Console.WriteLine("=========================================");
|
||||||
Console.WriteLine("Geekbot Disconnected from the Discord Gateway...");
|
Console.WriteLine("Geekbot Disconnected from the Discord Gateway...");
|
||||||
Console.WriteLine(exception.Message);
|
Console.WriteLine(exception.Message);
|
||||||
Console.WriteLine("Attempting Reconnect...");
|
Console.WriteLine("Attempting Reconnect...");
|
||||||
Console.WriteLine("=========================================");
|
Console.WriteLine("=========================================");
|
||||||
await client.StopAsync();
|
await client.StopAsync();
|
||||||
System.Threading.Thread.Sleep(10000);
|
System.Threading.Thread.Sleep(10000);
|
||||||
await Login();
|
await Login();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task FinishStartup()
|
public async Task FinishStartup()
|
||||||
{
|
{
|
||||||
await client.SetGameAsync("Ping Pong");
|
await client.SetGameAsync("Ping Pong");
|
||||||
Console.WriteLine($"Now Connected to {client.Guilds.Count} Servers");
|
Console.WriteLine($"Now Connected to {client.Guilds.Count} Servers");
|
||||||
|
|
||||||
Console.WriteLine("Registering Stuff");
|
Console.WriteLine("Registering Stuff");
|
||||||
|
|
||||||
client.MessageReceived += HandleCommand;
|
client.MessageReceived += HandleCommand;
|
||||||
client.MessageReceived += HandleMessageReceived;
|
client.MessageReceived += HandleMessageReceived;
|
||||||
client.UserJoined += HandleUserJoined;
|
client.UserJoined += HandleUserJoined;
|
||||||
client.Disconnected += Reconnect;
|
// client.Disconnected += Reconnect;
|
||||||
await commands.AddModulesAsync(Assembly.GetEntryAssembly());
|
await commands.AddModulesAsync(Assembly.GetEntryAssembly());
|
||||||
|
|
||||||
Console.WriteLine("Done and ready for use...\n");
|
Console.WriteLine("Done and ready for use...\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task HandleCommand(SocketMessage messageParam)
|
public async Task HandleCommand(SocketMessage messageParam)
|
||||||
{
|
{
|
||||||
var message = messageParam as SocketUserMessage;
|
var message = messageParam as SocketUserMessage;
|
||||||
if (message == null) return;
|
if (message == null) return;
|
||||||
if (message.Author.Username.Equals(client.CurrentUser.Username)) return;
|
if (message.Author.Username.Equals(client.CurrentUser.Username)) return;
|
||||||
int argPos = 0;
|
int argPos = 0;
|
||||||
if (message.ToString().ToLower().StartsWith("ping"))
|
if (message.ToString().ToLower().StartsWith("ping"))
|
||||||
{
|
{
|
||||||
await message.Channel.SendMessageAsync("pong");
|
await message.Channel.SendMessageAsync("pong");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (message.ToString().ToLower().StartsWith("hui"))
|
if (message.ToString().ToLower().StartsWith("hui"))
|
||||||
{
|
{
|
||||||
await message.Channel.SendMessageAsync("hui!!!");
|
await message.Channel.SendMessageAsync("hui!!!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (message.ToString().ToLower().Contains("teamspeak") || message.ToString().ToLower().Contains("skype"))
|
if (message.ToString().ToLower().Contains("teamspeak") || message.ToString().ToLower().Contains("skype"))
|
||||||
{
|
{
|
||||||
await message.Channel.SendMessageAsync("How dare you to use such a filthy word in here http://bit.ly/2poL2IZ");
|
await message.Channel.SendMessageAsync("How dare you to use such a filthy word in here http://bit.ly/2poL2IZ");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!(message.HasCharPrefix('!', ref argPos) || message.HasMentionPrefix(client.CurrentUser, ref argPos))) return;
|
if (!(message.HasCharPrefix('!', ref argPos) || message.HasMentionPrefix(client.CurrentUser, ref argPos))) return;
|
||||||
var context = new CommandContext(client, message);
|
var context = new CommandContext(client, message);
|
||||||
Task.Run(() => commands.ExecuteAsync(context, argPos, map));
|
Task.Run(() => commands.ExecuteAsync(context, argPos, map));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task HandleMessageReceived(SocketMessage messsageParam)
|
public async Task HandleMessageReceived(SocketMessage messsageParam)
|
||||||
{
|
{
|
||||||
var message = messsageParam;
|
var message = messsageParam;
|
||||||
if (message == null) return;
|
if (message == null) return;
|
||||||
|
|
||||||
var channel = (SocketGuildChannel)message.Channel;
|
var channel = (SocketGuildChannel)message.Channel;
|
||||||
|
|
||||||
Console.WriteLine(channel.Guild.Name + " - " + message.Channel + " - " + message.Author.Username + " - " + message.Content);
|
Console.WriteLine(channel.Guild.Name + " - " + message.Channel + " - " + message.Author.Username + " - " + message.Content);
|
||||||
|
|
||||||
var statsRecorder = new StatsRecorder(message, redis);
|
var statsRecorder = new StatsRecorder(message, redis);
|
||||||
Task.Run(() => statsRecorder.UpdateUserRecordAsync());
|
Task.Run(() => statsRecorder.UpdateUserRecordAsync());
|
||||||
Task.Run(() => statsRecorder.UpdateGuildRecordAsync());
|
Task.Run(() => statsRecorder.UpdateGuildRecordAsync());
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task HandleUserJoined(SocketGuildUser user)
|
public async Task HandleUserJoined(SocketGuildUser user)
|
||||||
{
|
{
|
||||||
if (!user.IsBot)
|
if (!user.IsBot)
|
||||||
{
|
{
|
||||||
var message = redis.Client.StringGet(user.Guild.Id + "-welcomeMsg");
|
var message = redis.Client.StringGet(user.Guild.Id + "-welcomeMsg");
|
||||||
if (!message.IsNullOrEmpty)
|
if (!message.IsNullOrEmpty)
|
||||||
{
|
{
|
||||||
message = message.ToString().Replace("$user", user.Mention);
|
message = message.ToString().Replace("$user", user.Mention);
|
||||||
await user.Guild.DefaultChannel.SendMessageAsync(message);
|
await user.Guild.DefaultChannel.SendMessageAsync(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue