forked from soxtoby/SlackNet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HubIdentifier.cs
64 lines (49 loc) · 2.23 KB
/
HubIdentifier.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
using System;
using System.Threading.Tasks;
namespace SlackNet.Bot;
[Obsolete("Use ConversationIdentifier instead")]
public abstract class HubIdentifier
{
public abstract Task<string> HubId(ISlackBot bot);
public static implicit operator HubIdentifier(string name) =>
name?[0] == '@' ? new ImByName(name)
: name?[0] == '#' ? (HubIdentifier)new ChannelByName(name)
: new GroupByName(name);
public static implicit operator HubIdentifier(Hub hub) => new HubByRef(hub);
public static implicit operator HubIdentifier(Conversation conversation) => new HubByConversationIdentifier(conversation);
public static implicit operator HubIdentifier(ConversationIdentifier conversationIdentifier) => new HubByConversationIdentifier(conversationIdentifier);
}
[Obsolete("Use ConversationByRef instead")]
public class HubByRef : HubIdentifier
{
private readonly Hub _hub;
public HubByRef(Hub hub) => _hub = hub;
public override Task<string> HubId(ISlackBot bot) => Task.FromResult(_hub.Id);
}
[Obsolete("Use ConversationByName instead")]
public class ChannelByName : HubIdentifier
{
private readonly string _name;
public ChannelByName(string name) => _name = name;
public override Task<string> HubId(ISlackBot bot) => Task.FromResult(_name);
}
[Obsolete("Use ConversationByName instead")]
public class GroupByName : HubIdentifier
{
private readonly string _name;
public GroupByName(string name) => _name = name;
public override Task<string> HubId(ISlackBot bot) => Task.FromResult(_name);
}
[Obsolete("Use ConversationByName instead")]
public class ImByName : HubIdentifier
{
private readonly string _name;
public ImByName(string name) => _name = name;
public override async Task<string> HubId(ISlackBot bot) => (await bot.GetImByName(_name.Substring(1)).ConfigureAwait(false)).Id;
}
class HubByConversationIdentifier : HubIdentifier
{
private readonly ConversationIdentifier _conversationIdentifier;
public HubByConversationIdentifier(ConversationIdentifier conversationIdentifier) => _conversationIdentifier = conversationIdentifier;
public override Task<string> HubId(ISlackBot bot) => _conversationIdentifier.ConversationId(bot);
}