Skip to content

Commit

Permalink
Add emoji alias support 😎 (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamaln7 authored Jul 23, 2019
1 parent 3ab7cd8 commit 04cc3b7
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
50 changes: 50 additions & 0 deletions alias/emoji/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package emoji

import (
"math/rand"
"strings"
"time"

"github.com/kamaln7/klein/alias"
)

// Provider implements an alias generator
type Provider struct {
Config *Config
}

// ensure that the storage.Provider interface is implemented
var _ alias.Provider = new(Provider)

// Config contains the configuration for the file storage
type Config struct {
Length int
randSource *rand.Rand
}

var emojis = []string{"👍", "👎", "👽", "👼", "😠", "😧", "😲", "👟", "👶", "👙", "👱", "👱‍♀️", "😊", "👢", "🙇", "🙇‍", "👦", "👰", "💼", "👤", "👥", "🤙", "👏", "🌂", "🤡", "😰", "😖", "😕", "👷", "👷‍♀️", "👫", "👨‍❤️‍👨", "💑", "👩‍❤️‍👩", "👨‍❤️‍💋‍👨", "💏", "👩‍❤️‍💋‍👩", "🤠", "🤞", "👑", "😢", "😿", "💃", "👯‍♂️", "👯", "🕶", "😞", "😥", "😵", "👗", "🤤", "👂", "😑", "👁", "👓", "👀", "🤕", "🤒", "👊", "👨‍👦", "👨‍👦‍👦", "👨‍👧", "👨‍👧‍👦", "👨‍👧‍👧", "👨‍👨‍👦", "👨‍👨‍👦‍👦", "👨‍👨‍👧", "👨‍👨‍👧‍👦", "👨‍👨‍👧‍👧", "👪", "👨‍👩‍👦‍👦", "👨‍👩‍👧", "👨‍👩‍👧‍👦", "👨‍👩‍👧‍👧", "👩‍👦", "👩‍👦‍👦", "👩‍👧", "👩‍👧‍👦", "👩‍👧‍👧", "👩‍👩‍👦", "👩‍👩‍👦‍👦", "👩‍👩‍👧", "👩‍👩‍👧‍👦", "👩‍👩‍👧‍👧", "😨", "🕵️‍♀️", "✊", "🤛", "🤜", "😳", "👣", "😦", "☹", "🙍‍♂️", "🙍", "🖕", "👻", "👧", "😬", "😁", "😀", "💂", "💂‍♀️", "💇‍♂️", "💇", "👜", "🤝", "😍", "😻", "👠", "🤗", "😯", "👿", "😇", "👺", "👹", "👖", "😂", "😹", "👘", "💋", "😗", "😽", "😚", "😘", "😙", "😆", "👄", "💄", "🤥", "🕵", "👨", "👨‍🎨", "👨‍🚀", "👨‍🍳", "🕺", "🤦", "👨‍🏭", "👨‍🌾", "👨‍🚒", "👨‍⚕️", "🤵", "👨‍⚖️", "👨‍🔧", "👨‍💼", "👨‍✈️", "👨‍🔬", "🤷‍♂️", "👨‍🎤", "👨‍🎓", "👨‍🏫", "👨‍💻", "👲", "👳", "👞", "😷", "💆‍♂️", "💆", "🤘", "🤑", "🎓", "🤶", "💪", "💅", "🤢", "👔", "🤓", "😐", "🙅‍♂️", "🙅", "😶", "👃", "👌", "🙆‍♂️", "🙆", "👴", "👵", "👐", "😮", "😔", "😣", "👇", "👈", "👉", "☝", "👆", "👮", "👮‍♀️", "💩", "👝", "😾", "🙎‍♂️", "🙎", "🙏", "🤰", "🤴", "👸", "👛", "😡", "🤚", "✋", "🖐", "🙌", "🙋‍♂️", "🙋", "☺️", "😌", "⛑", "💍", "🤖", "🤣", "🙄", "🏃", "🏃‍♀️", "👡", "🎅", "🎒", "😱", "🙀", "🤳", "💀", "😴", "😪", "🙁", "🙂", "😄", "😸", "😃", "😺", "😈", "😏", "😼", "🤧", "😭", "🗣", "😛", "😝", "😜", "😎", "😓", "😅", "🤔", "💁‍♂️", "💁", "😫", "👅", "🎩", "😤", "👕", "👬", "👭", "😒", "🙃", "✌", "🖖", "🚶", "🚶‍♀️", "👋", "😩", "😉", "👩", "👩‍🎨", "👩‍🚀", "👩‍🍳", "🤦‍♀️", "👩‍🏭", "👩‍🌾", "👩‍🚒", "👩‍⚕️", "👩‍⚖️", "👩‍🔧", "👩‍💼", "👩‍✈️", "👩‍🔬", "🤷", "👩‍🎤", "👩‍🎓", "👩‍🏫", "👩‍💻", "👳‍♀️", "👚", "👒", "😟", "✍", "😋", "🤐", "💤", "🐜", "🐤", "🎍", "🦇", "🐻", "🐞", "🐦", "🌼", "🐡", "🐗", "💥", "💐", "🐛", "🦋", "🌵", "🐫", "🐱", "🐈", "🌸", "🌰", "🐔", "🐿", "🎄", "☁️", "🌩", "⛈", "🌧", "🌨", "☄", "🐮", "🐄", "🦀", "🌙", "🐊", "💨", "🌳", "🦌", "💫", "🐶", "🐕", "🐬", "🕊", "🐉", "🐲", "🐪", "💧", "🦆", "🦅", "🌾", "🌍", "🌎", "🌏", "🐘", "🌲", "🍂", "🔥", "🌓", "🌛", "🐟", "🌫", "🍀", "🦊", "🐸", "🌕", "🌝", "🐐", "🦍", "🐹", "🐥", "🐣", "🙉", "🌿", "🌺", "🐝", "🐴", "🎃", "🐨", "🌗", "🌜", "🍃", "🐆", "🦁", "🦎", "🍁", "🐒", "🐵", "🐭", "🐁", "🍄", "🌑", "🌚", "🌊", "🐙", "☂", "🦉", "🐂", "🌴", "🐼", "⛅", "🐾", "🐧", "🐷", "🐖", "🐽", "🐩", "🐰", "🐇", "🐎", "🐏", "🐀", "🦏", "🐓", "🌹", "🦂", "🙈", "🌱", "☘", "🦈", "🐑", "🐚", "🦐", "🐌", "🐍", "❄️", "⛄", "☃", "✨", "🙊", "🕷", "🕸", "🦑", "⭐", "🌟", "🌥", "🌦", "🌤", "🌞", "🌻", "☀️", "💦", "🎋", "🐯", "🐅", "🌪", "🐠", "🌷", "🦃", "🐢", "☔", "🦄", "🌘", "🌖", "🐃", "🌒", "🌔", "🐳", "🐋", "🥀", "🌬", "🐺", "⚡", "🍎", "🥑", "🍼", "🥓", "🥖", "🍌", "🍺", "🍻", "🍱", "🎂", "🍞", "🌯", "🍰", "🍬", "🥕", "🍾", "🧀", "🍒", "🍫", "🥂", "🍸", "☕", "🍪", "🌽", "🥐", "🥒", "🍛", "🍮", "🍡", "🍩", "🥚", "🍆", "🍥", "🍴", "🍳", "🍤", "🍟", "🍇", "🍏", "🥗", "🍔", "🍯", "🌶", "🌭", "🍨", "🍦", "🥝", "🍋", "🍭", "🍖", "🍈", "🥛", "🍢", "🥞", "🍑", "🥜", "🍐", "🍍", "🍕", "🍽", "🍿", "🥔", "🍗", "🍜", "🍚", "🍙", "🍘", "🍶", "🥘", "🍧", "🍝", "🥄", "🍲", "🍓", "🥙", "🍣", "🍠", "🌮", "🍊", "🍵", "🍅", "🍹", "🥃", "🍉", "🍷", "🥇", "🥈", "🥉", "🎱", "🎨", "🏸", "⚾", "🏀", "⛹", "⛹️‍♀️", "🛀", "🚴", "🚴‍♀️", "🏹", "🎳", "🥊", "🕴", "🎪", "🎬", "🏏", "🎯", "🥁", "🏑", "🎣", "🏈", "🎲", "🥅", "⛳", "🏌", "🏌️‍♀️", "🎸", "🎧", "🏇", "🏒", "⛸", "🤸‍♂️", "🤹‍♂️", "🤾‍♂️", "🤽‍♂️", "🥋", "🎖", "🏅", "🤼‍♂️", "🎤", "🚵", "🚵‍♀️", "🎹", "🎼", "🎭", "🤺", "🏓", "🎗", "🏵", "🚣", "🚣‍♀️", "🏉", "🎽", "🎷", "🎿", "⛷", "🎰", "🏂", "⚽", "👾", "🏄", "🏄‍♀️", "🏊", "🏊‍♀️", "🎾", "🎫", "🎟", "🏆", "🎺", "🎮", "🎻", "🏐", "🏋", "🏋️‍♀️", "🤸‍♀️", "🤹‍♀️", "🤾‍♀️", "🤽‍♀️", "🤼‍♀️", "🚡", "✈️", "🚑", "⚓", "🚛", "🛰", "🏦", "🏖", "🚲", "🚙", "🌉", "🏗", "🚅", "🚄", "🚌", "🚏", "🏕", "🛶", "🎠", "🏁", "⛪", "🌇", "🌆", "🏙", "🏛", "🚧", "🏪", "🏬", "🏚", "🏜", "🏝", "🏰", "🏤", "🏭", "🎡", "⛴", "🚒", "🎆", "🛬", "🛫", "🌁", "⛲", "⛽", "🚁", "🏥", "🏨", "🏠", "🏡", "🏘", "🗾", "🏯", "🕋", "🛴", "🚈", "🏩", "🚇", "🌌", "🚐", "🚝", "🕌", "🛥", "🛵", "🏍", "🛣", "🗻", "⛰", "🚠", "🚞", "🏔", "🏞", "🌃", "🏢", "🚘", "🚍", "🚔", "🚖", "🛳", "🚓", "🏣", "🏎", "🚃", "🛤", "🌈", "🚗", "🎑", "🚀", "🎢", "🚨", "⛵", "🏫", "💺", "⛩", "🚢", "🛩", "🎇", "🚤", "🏟", "🌠", "🚉", "🗽", "🚂", "🌅", "🌄", "🚟", "🕍", "🚕", "⛺", "🗼", "🚜", "🚥", "🚋", "🚆", "🚊", "🚎", "🚚", "🚦", "🌋", "💒", "⏰", "⚗", "🏺", "⚖", "🎈", "🗳", "📊", "💈", "🛁", "🔋", "🛏", "🛎", "🏴", "✒️", "📘", "💣", "🔖", "📑", "📚", "💡", "📆", "📲", "📷", "📸", "🕯", "🗃", "📇", "🗂", "💿", "⛓", "📉", "📈", "🗜", "📋", "📕", "🔐", "⚰", "💻", "🖱", "🎊", "🎛", "🛋", "🖍", "💳", "🎌", "⚔", "🔮", "🗡", "📅", "🖥", "💵", "🎎", "🚪", "📀", "📧", "🔌", "✉️", "📩", "💶", "📠", "🗄", "📁", "📽", "🎞", "🎏", "🔦", "💾", "🖋", "🖼", "⚱", "⚙", "💎", "🎁", "📗", "🔫", "🔨", "⚒", "🛠", "🔪", "🕳", "⌛", "⏳", "📥", "📨", "📱", "🏮", "🕹", "🔑", "⌨", "🏷", "📒", "🎚", "🔗", "🔒", "🔏", "💌", "🔍", "🔎", "📫", "📪", "📬", "📭", "🕰", "📝", "🔬", "💽", "💸", "💰", "🎥", "🗿", "📰", "🗞", "📓", "📔", "🔩", "🛢", "🗝", "📖", "📂", "📙", "📤", "📦", "📄", "📃", "📟", "🖌", "📎", "🖇", "⛱", "🖊", "✏️", "☎️", "⛏", "💊", "📯", "📮", "💷", "📿", "🖨", "📌", "📻", "🏳️‍🌈", "🎀", "📍", "📡", "✂️", "📜", "🛡", "🛍", "🛒", "🚿", "☠", "🛌", "🚬", "🗓", "🗒", "⏱", "📏", "🎙", "💉", "🎉", "📞", "🔭", "🌡", "⏲", "🚽", "🖲", "🚩", "📐", "📺", "🔓", "📼", "📹", "🗑", "⌚", "🏳", "🎐", "🗺", "🔧", "💴", "💯", "🔢", "🅰️", "🆎", "🔤", "🔡", "🉑", "💢", "♒", "♈", "◀️", "⏬", "⏫", "⬇️", "🔽", "▶️", "⤵️", "⤴️", "⬅️", "↙️", "↘️", "➡️", "↪️", "⬆️", "↕️", "🔼", "↖️", "↗️", "🔃", "🔄", "*⃣", "🏧", "⚛", "🅱️", "🚼", "🔙", "🛄", "☑️", "‼️", "🔰", "🔔", "☣", "⚫", "🖤", "🃏", "⬛", "◾", "◼️", "▪️", "🔲", "💙", "💔", "♋", "🔠", "♑", "💹", "🚸", "🎦", "🆑", "🕐", "🕙", "🕥", "🕚", "🕦", "🕛", "🕧", "🕜", "🕑", "🕝", "🕒", "🕞", "🕓", "🕟", "🕔", "🕠", "🕕", "🕡", "🕖", "🕢", "🕗", "🕣", "🕘", "🕤", "♣️", "㊗️", "🆒", "©️", "💘", "➰", "💱", "🛃", "🌀", "💠", "♦️", "🚯", "8️⃣", "✴️", "✳️", "🔚", "❗", "⏩", "5️⃣", "⚜", "🎴", "4️⃣", "🆓", "♊", "💝", "🌐", "💚", "❕", "❔", "#️⃣", "❤️", "💟", "💓", "💗", "♥️", "✔️", "➗", "💲", "❣", "➖", "✖️", "➕", "🔆", "♨️", "🆔", "🉐", "ℹ️", "⁉️", "🔟", "🈁", "🔵", "🔷", "🔶", "✝", "🛅", "↔️", "↩️", "♌", "♎", "➿", "🔊", "📢", "🔅", "Ⓜ️", "🀄", "📣", "🕎", "🚹", "📴", "🎵", "🔇", "📛", "❎", "🆕", "⏭", "🆖", "9️⃣", "🔕", "🚳", "⛔", "🚫", "📵", "🚷", "🚭", "🚱", "🎶", "⭕", "🅾️", "🆗", "🕉", "🔛", "1️⃣", "⛎", "☦", "🅿️", "〽️", "🛂", "⏸", "☮", "♓", "🛐", "⏯", "🚰", "⏮", "💜", "🚮", "❓", "🔘", "☢", "⏺", "♻️", "🔴", "®️", "🔁", "🔂", "🚻", "💞", "⏪", "🗯", "🈂️", "♐", "♏", "㊙️", "7️⃣", "📶", "6️⃣", "🔯", "🔹", "🔸", "🔺", "🔻", "🔜", "🆘", "🔉", "♠️", "❇️", "💖", "🔈", "💬", "☪", "✡", "⏹", "🛑", "🔣", "♉", "💭", "3️⃣", "™️", "🔝", "🔱", "🔀", "2️⃣", "💕", "🈹", "🈴", "🈺", "🈯", "🈷️", "🈶", "🈵", "🈚", "🈸", "🈲", "🈳", "🔞", "🆙", "📳", "♍", "🆚", "⚠️", "〰️", "🚾", "☸", "♿", "✅", "⚪", "💮", "⬜", "◽", "◻️", "▫️", "🔳", "🚺", "❌", "💛", "☯", "0️⃣", "🇦🇫", "🇦🇽", "🇦🇱", "🇩🇿", "🇦🇸", "🇦🇩", "🇦🇴", "🇦🇮", "🇦🇶", "🇦🇬", "🇦🇷", "🇦🇲", "🇦🇼", "🇦🇺", "🇦🇹", "🇦🇿", "🇧🇸", "🇧🇭", "🇧🇩", "🇧🇧", "🇧🇾", "🇧🇪", "🇧🇿", "🇧🇯", "🇧🇲", "🇧🇹", "🇧🇴", "🇧🇦", "🇧🇼", "🇧🇷", "🇮🇴", "🇻🇬", "🇧🇳", "🇧🇬", "🇧🇫", "🇧🇮", "🇰🇭", "🇨🇲", "🇨🇦", "🇮🇨", "🇨🇻", "🇧🇶", "🇰🇾", "🇨🇫", "🇹🇩", "🇨🇱", "🇨🇽", "🇨🇳", "🇨🇨", "🇨🇴", "🇰🇲", "🇨🇬", "🇨🇩", "🇨🇰", "🇨🇷", "🇨🇮", "🇭🇷", "🇨🇺", "🇨🇼", "🇨🇾", "🇨🇿", "🇩🇪", "🇩🇰", "🇩🇯", "🇩🇲", "🇩🇴", "🇪🇨", "🇪🇬", "🇸🇻", "🇬🇶", "🇪🇷", "🇪🇸", "🇪🇪", "🇪🇹", "🇪🇺", "🇫🇰", "🇫🇴", "🇫🇯", "🇫🇮", "🇫🇷", "🇬🇫", "🇵🇫", "🇹🇫", "🇬🇦", "🇬🇲", "🇬🇪", "🇬🇭", "🇬🇮", "🇬🇷", "🇬🇱", "🇬🇩", "🇬🇵", "🇬🇺", "🇬🇹", "🇬🇬", "🇬🇳", "🇬🇼", "🇬🇾", "🇭🇹", "🇭🇳", "🇭🇰", "🇭🇺", "🇮🇸", "🇮🇳", "🇮🇩", "🇮🇷", "🇮🇶", "🇮🇪", "🇮🇲", "🇮🇱", "🇮🇹", "🇯🇲", "🇯🇪", "🇯🇴", "🇯🇵", "🇰🇿", "🇰🇪", "🇰🇮", "🇽🇰", "🇰🇷", "🇰🇼", "🇰🇬", "🇱🇦", "🇱🇻", "🇱🇧", "🇱🇸", "🇱🇷", "🇱🇾", "🇱🇮", "🇱🇹", "🇱🇺", "🇲🇴", "🇲🇰", "🇲🇬", "🇲🇼", "🇲🇾", "🇲🇻", "🇲🇱", "🇲🇹", "🇲🇭", "🇲🇶", "🇲🇷", "🇲🇺", "🇾🇹", "🇲🇽", "🇫🇲", "🇲🇩", "🇲🇨", "🇲🇳", "🇲🇪", "🇲🇸", "🇲🇦", "🇲🇿", "🇲🇲", "🇳🇦", "🇳🇷", "🇳🇵", "🇳🇱", "🇳🇨", "🇳🇿", "🇳🇮", "🇳🇪", "🇳🇬", "🇳🇺", "🇳🇫", "🇰🇵", "🇲🇵", "🇳🇴", "🇴🇲", "🇵🇰", "🇵🇼", "🇵🇸", "🇵🇦", "🇵🇬", "🇵🇾", "🇵🇪", "🇵🇭", "🇵🇳", "🇵🇱", "🇵🇹", "🇵🇷", "🇶🇦", "🇷🇪", "🇷🇴", "🇷🇺", "🇷🇼", "🇼🇸", "🇸🇲", "🇸🇹", "🇸🇦", "🇸🇳", "🇷🇸", "🇸🇨", "🇸🇱", "🇸🇬", "🇸🇽", "🇸🇰", "🇸🇮", "🇸🇧", "🇸🇴", "🇿🇦", "🇬🇸", "🇸🇸", "🇱🇰", "🇧🇱", "🇸🇭", "🇰🇳", "🇱🇨", "🇵🇲", "🇻🇨", "🇸🇩", "🇸🇷", "🇸🇿", "🇸🇪", "🇨🇭", "🇸🇾", "🇹🇼", "🇹🇯", "🇹🇿", "🇹🇭", "🇹🇱", "🇹🇬", "🇹🇰", "🇹🇴", "🇹🇷", "🇹🇹", "🇹🇳", "🇹🇲", "🇹🇨", "🇹🇻", "🇺🇬", "🇬🇧", "🇺🇦", "🇦🇪", "🇺🇾", "🇺🇸", "🇻🇮", "🇺🇿", "🇻🇺", "🇻🇦", "🇻🇪", "🇻🇳", "🇼🇫", "🇪🇭", "🇾🇪", "🇿🇲", "🇿🇼"}

// New initializes the alias generator and returns a new instance
func New(c *Config) *Provider {
c.randSource = rand.New(rand.NewSource(time.Now().UnixNano()))

provider := &Provider{
Config: c,
}

return provider
}

// Generate returns a random alias
func (p *Provider) Generate() string {
var (
b strings.Builder
n = len(emojis)
)

for i := 0; i < p.Config.Length; i++ {
b.WriteString(emojis[p.Config.randSource.Intn(n)])
}

return b.String()
}
9 changes: 8 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/kamaln7/klein/alias"
"github.com/kamaln7/klein/alias/alphanumeric"
"github.com/kamaln7/klein/alias/emoji"
"github.com/kamaln7/klein/alias/memorable"
"github.com/kamaln7/klein/auth"
"github.com/kamaln7/klein/auth/httpbasic"
Expand Down Expand Up @@ -182,6 +183,10 @@ var rootCmd = &cobra.Command{
if err != nil {
logger.Fatalf("could not select alphanumeric alias: %s\n", err.Error())
}
case "emoji":
aliasProvider = emoji.New(&emoji.Config{
Length: viper.GetInt("alias.emoji.length"),
})
case "memorable":
aliasProvider = memorable.New(&memorable.Config{
Length: viper.GetInt("alias.memorable.length"),
Expand Down Expand Up @@ -223,12 +228,14 @@ func init() {
rootCmd.PersistentFlags().String("root", "", "root redirect")

// Alias options
rootCmd.PersistentFlags().String("alias.driver", "alphanumeric", "what alias generation to use (alphanumeric, memorable)")
rootCmd.PersistentFlags().String("alias.driver", "alphanumeric", "what alias generation to use (alphanumeric, emoji, memorable)")

rootCmd.PersistentFlags().Int("alias.alphanumeric.length", 5, "alphanumeric code length")
rootCmd.PersistentFlags().Bool("alias.alphanumeric.alpha", true, "use letters in code")
rootCmd.PersistentFlags().Bool("alias.alphanumeric.num", true, "use numbers in code")

rootCmd.PersistentFlags().Int("alias.emoji.length", 6, "emoji count")

rootCmd.PersistentFlags().Int("alias.memorable.length", 3, "memorable word count")

// Auth options
Expand Down

0 comments on commit 04cc3b7

Please sign in to comment.