Allow setting the channel ID
This commit is contained in:
parent
265c77fd1d
commit
7f0acaeabf
1 changed files with 15 additions and 8 deletions
|
@ -37,7 +37,8 @@ namespace GCDC
|
||||||
if (!RuntimeCommands.HasRegistered("dc"))
|
if (!RuntimeCommands.HasRegistered("dc"))
|
||||||
RuntimeCommands.Register<string>("dc", SendMessage);
|
RuntimeCommands.Register<string>("dc", SendMessage);
|
||||||
if (!RuntimeCommands.HasRegistered("dcsetup"))
|
if (!RuntimeCommands.HasRegistered("dcsetup"))
|
||||||
RuntimeCommands.Register<string>("dcsetup", Setup);
|
RuntimeCommands.Register<string>("dcsetup", Setup,
|
||||||
|
"Initial setup for GCDC. The argument is the channel ID first.");
|
||||||
if (File.Exists("gcdc.json"))
|
if (File.Exists("gcdc.json"))
|
||||||
{
|
{
|
||||||
var jo = JObject.Load(new JsonTextReader(File.OpenText("gcdc.json")));
|
var jo = JObject.Load(new JsonTextReader(File.OpenText("gcdc.json")));
|
||||||
|
@ -48,24 +49,30 @@ namespace GCDC
|
||||||
Start();
|
Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Setup(string token)
|
public void Setup(string tokenOrChannel)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(token))
|
if (!tokenOrChannel.Contains("-"))
|
||||||
{
|
{
|
||||||
|
if (!int.TryParse(tokenOrChannel, out _))
|
||||||
|
{
|
||||||
|
Log.Error("Bad format for channel ID.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Process.Start(
|
Process.Start(
|
||||||
"https://discordapp.com/oauth2/authorize?client_id=680138144812892371&redirect_uri=https%3A%2F%2Fgcdc.herokuapp.com%2Fapi%2Fusers%2Fregister&response_type=code&scope=identify&state=551075431336378398");
|
"https://discordapp.com/oauth2/authorize?client_id=680138144812892371&redirect_uri=https%3A%2F%2Fgcdc.herokuapp.com%2Fapi%2Fusers%2Fregister&response_type=code&scope=identify&state=" +
|
||||||
|
tokenOrChannel);
|
||||||
Log.Output(
|
Log.Output(
|
||||||
"Please authorize the GCDC app on the page that should open. This connection is only used to avoid account spam and to display your Discord name.");
|
"Please authorize the GCDC app on the page that should open. This connection is only used to avoid account spam and to display your Discord name.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_token = token;
|
_token = tokenOrChannel;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (JObject.Parse(WebUtils.Request("users/get?token=" + token))["response"].Value<string>() == "OK")
|
if (JObject.Parse(WebUtils.Request("users/get?token=" + tokenOrChannel))["response"].Value<string>() == "OK")
|
||||||
{
|
{
|
||||||
var jo = new JObject();
|
var jo = new JObject {["token"] = tokenOrChannel};
|
||||||
jo["token"] = token;
|
|
||||||
File.WriteAllText("gcdc.json", jo.ToString());
|
File.WriteAllText("gcdc.json", jo.ToString());
|
||||||
Start();
|
Start();
|
||||||
Log.Output(
|
Log.Output(
|
||||||
|
|
Loading…
Reference in a new issue