Finished off the discord enhancements

pull/3632/head
tidusjar 4 years ago
parent 31060fff61
commit 466c9dada7

@ -121,16 +121,27 @@ namespace Ombi.Notifications.Agents
fields.Add(new DiscordField { name = "Denied Reason", value = denyReason, inline = true });
}
}
var color = string.Empty;
if (model.Data.TryGetValue("RequestStatus", out var status))
{
if (status.HasValue())
{
fields.Add(new DiscordField { name = "Status", value = status, inline = true });
color = status switch
{
"Available" => "51283",
"Denied" => "13959168",
"Processing Request" => "37354",
"Pending Approval" => "16754470"
};
}
}
var author = new DiscordAuthor
{
iconurl = settings.Icon.HasValue() ? settings.Icon : string.Empty
};
if (model.Data.TryGetValue("ApplicationUrl", out var appUrl))
@ -142,10 +153,13 @@ namespace Ombi.Notifications.Agents
author.name = appName;
}
var embed = new DiscordEmbeds
{
fields = fields,
author = author
author = author,
color = color
};
if (model.Data.TryGetValue("Title", out var title))
@ -162,8 +176,10 @@ namespace Ombi.Notifications.Agents
embed.thumbnail = new DiscordImage { url = image };
}
discordBody.embeds = new List<DiscordEmbeds> { embed };
if (model.Data.Any())
{
discordBody.embeds = new List<DiscordEmbeds> { embed };
}
await Api.SendMessage(discordBody, settings.WebHookId, settings.Token);
}
catch (Exception e)

@ -9,6 +9,6 @@ namespace Ombi.Notifications.Models
public string To { get; set; }
public Dictionary<string, string> Other { get; set; } = new Dictionary<string, string>();
public IDictionary<string, string> Data { get; set; }
public IDictionary<string, string> Data { get; set; } = new Dictionary<string, string>();
}
}

@ -8,6 +8,7 @@ namespace Ombi.Settings.Settings.Models.Notifications
public bool Enabled { get; set; }
public string WebhookUrl { get; set; }
public string Username { get; set; }
public string Icon { get; set; }
[JsonIgnore]
public string WebHookId => SplitWebUrl(4);

@ -58,6 +58,7 @@ export enum NotificationType {
export interface IDiscordNotifcationSettings extends INotificationSettings {
webhookUrl: string;
username: string;
icon: string;
notificationTemplates: INotificationTemplates[];
}

@ -25,8 +25,17 @@
<input matInput formControlName="username">
</mat-form-field>
</div>
<div class="md-form-field">
<mat-form-field appearance="outline">
<mat-label>Icon</mat-label>
<input matInput formControlName="icon">
</mat-form-field>
<div>
<img [src]="form.value.icon" style="width: 300px" />
</div>
</div>
</div>
<div class="row">
<div class="row top-space">
<div class="form-group">
<div>

@ -29,6 +29,7 @@ export class DiscordComponent implements OnInit {
enabled: [x.enabled],
username: [x.username],
webhookUrl: [x.webhookUrl, [Validators.required]],
icon: [x.icon]
});
});

Loading…
Cancel
Save