Skip to content

Instantly share code, notes, and snippets.

@MihaZupan
Last active June 8, 2019 21:38
Show Gist options
  • Save MihaZupan/fc55672e78091b2e5f21da311ff5c7d0 to your computer and use it in GitHub Desktop.
Save MihaZupan/fc55672e78091b2e5f21da311ff5c7d0 to your computer and use it in GitHub Desktop.
public long GetBucket(Update update)
{
if (update.Message is Message message)
return message.Chat.Id;
if (update.ChosenInlineResult is ChosenInlineResult chosenInlineResult)
return chosenInlineResult.From.Id;
if (update.InlineQuery is InlineQuery inlineQuery)
return inlineQuery.From.Id;
if (update.CallbackQuery is CallbackQuery callbackQuery)
return callbackQuery.Message?.Chat.Id ?? callbackQuery.From.Id;
if (update.ChannelPost is Message channelPost)
return channelPost.Chat.Id;
if (update.EditedMessage is Message editedMessage)
return editedMessage.Chat.Id;
if (update.EditedChannelPost is Message editedChannelPost)
return editedChannelPost.Chat.Id;
if (update.PreCheckoutQuery is PreCheckoutQuery preCheckoutQuery)
return preCheckoutQuery.From.Id;
if (update.ShippingQuery is ShippingQuery shippingQuery)
return shippingQuery.From.Id;
// Left-over: polls
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment