This repository has been archived by the owner on Nov 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDemocracyBot.cs
101 lines (95 loc) · 3.81 KB
/
DemocracyBot.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using System.Text;
using System.IO;
using System.Linq;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using System.Net.Http;
using Discord.Net;
using Discord;
using Discord.WebSocket;
using System.Diagnostics;
using FreneticUtilities.FreneticExtensions;
using FreneticUtilities.FreneticDataSyntax;
using DiscordBotBase;
using DiscordBotBase.CommandHandlers;
using DemocracyDiscordBot.CommandHandlers;
namespace DemocracyDiscordBot
{
/// <summary>
/// General program entry and handler.
/// </summary>
public class DemocracyBot
{
/// <summary>
/// The ID of the guild this bot is for.
/// </summary>
public static ulong OwningGuildID;
/// <summary>
/// The FDS Section of current vote topics.
/// </summary>
public static FDSSection VoteTopicsSection;
public static HashSet<ulong> Admins;
/// <summary>
/// Save the config, after any votes are cast.
/// </summary>
public static void Save()
{
DiscordBotBaseHelper.CurrentBot.SaveConfig();
}
/// <summary>
/// Helper method to determine if a user is a bot admin.
/// </summary>
public static bool IsAdmin(IUser user)
{
return Admins.Contains(user.Id);
}
/// <summary>
/// Software entry point - starts the bot.
/// </summary>
static void Main(string[] args)
{
DiscordBotBaseHelper.StartBotHandler(args, new DiscordBotConfig()
{
CommandPrefix = "!",
Initialize = (bot) =>
{
InfoCommands infoCommands = new InfoCommands() { Bot = bot };
VotingCommands voteCommands = new VotingCommands() { Bot = bot };
CoreCommands coreCommands = new CoreCommands(IsAdmin) { Bot = bot };
AdminCommands adminCommands = new AdminCommands() { Bot = bot };
OwningGuildID = bot.ConfigFile.GetUlong("guild_id").Value;
VoteTopicsSection = bot.ConfigFile.GetSection("vote_topics");
if (VoteTopicsSection == null)
{
VoteTopicsSection = new FDSSection();
bot.ConfigFile.Set("vote_topics", VoteTopicsSection);
}
Admins = new HashSet<ulong>(bot.ConfigFile.GetStringList("admins").Select(s => ulong.Parse(s)));
// Info
bot.RegisterCommand(infoCommands.CMD_Help, "help", "halp", "hlp", "hal", "hel", "h", "?", "use", "usage");
bot.RegisterCommand(infoCommands.CMD_Hello, "hello", "hi", "whoareyou", "what", "link", "info");
// Voting
bot.RegisterCommand(voteCommands.CMD_Ballot, "ballot", "b");
bot.RegisterCommand(voteCommands.CMD_Vote, "vote", "v");
bot.RegisterCommand(voteCommands.CMD_ClearVote, "clearvote", "voteclear", "cv");
// Admin
bot.RegisterCommand(coreCommands.CMD_Restart, "restart");
bot.RegisterCommand(adminCommands.CMD_CallVote, "callvote");
bot.RegisterCommand(adminCommands.CMD_EndVote, "endvote");
bot.Client.Ready += () =>
{
bot.Client.SetGameAsync("With the balance of power in this world.").Wait();
return Task.CompletedTask;
};
},
ShouldPayAttentionToMessage = (message) =>
{
return message.Channel is IPrivateChannel || IsAdmin(message.Author);
}
});
}
}
}