Skip to content

Commit

Permalink
Random room names, Topic specific room name
Browse files Browse the repository at this point in the history
Added randomNameGenerator sourced from Jitsi, and converted to Go. This gives more creative, and unique room names.
  • Loading branch information
Sean Sackowitz committed May 30, 2018
1 parent 8c249bb commit 21761e1
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# Build
/coverage.txt
/plugin.exe
/mattermost-zoom-plugin*.tar.gz
/mattermost-jitsi-plugin*.tar.gz
/dist
server/vendor
node_modules
Expand All @@ -26,3 +26,4 @@ webapp/dist
# Mac
*.swp
.DS_Store
package-lock.json
4 changes: 2 additions & 2 deletions plugin.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"id": "jitsi",
"name": "Jitsi",
"description": "Jitsi audio and video conferencing plugin for Mattermost.",
"version": "0.1.1",
"description": "Jitsi audio and video conferencing plugin for Mattermost. Follow https://github.com/seansackowitz/mattermost-plugin-jitsi for notifications on updates.",
"version": "0.2.0",
"backend": {
"executable": "server/plugin.exe"
},
Expand Down
30 changes: 22 additions & 8 deletions server/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"regexp"
"strings"
"sync/atomic"

Expand Down Expand Up @@ -67,6 +69,14 @@ type StartMeetingRequest struct {
MeetingId int `json:"meeting_id"`
}

func encodeJitsiMeetingID(meeting string) string {
reg, err := regexp.Compile("[^a-zA-Z0-9]+")
if err != nil {
log.Fatal(err)
}
return reg.ReplaceAllString(meeting, "")
}

func (p *Plugin) handleStartMeeting(w http.ResponseWriter, r *http.Request) {
userId := r.Header.Get("Mattermost-User-Id")

Expand All @@ -93,18 +103,22 @@ func (p *Plugin) handleStartMeeting(w http.ResponseWriter, r *http.Request) {
return
}

meetingId := userId + req.ChannelId
jitsiUrl := strings.TrimSpace(p.config().JitsiURL)
meetingUrl := jitsiUrl + "/" + meetingId
var meetingID string
meetingID = encodeJitsiMeetingID(req.Topic)
if len(req.Topic) < 1 {
meetingID = generateRoomWithoutSeparator()
}
jitsiURL := strings.TrimSpace(p.config().JitsiURL)
meetingURL := jitsiURL + "/" + meetingID

post := &model.Post{
UserId: user.Id,
ChannelId: req.ChannelId,
Message: fmt.Sprintf("Meeting started at %s.", meetingUrl),
Message: fmt.Sprintf("Meeting started at %s.", meetingURL),
Type: "custom_zoom",
Props: map[string]interface{}{
"meeting_id": meetingId,
"meeting_link": meetingUrl,
"meeting_id": meetingID,
"meeting_link": meetingURL,
"meeting_status": "STARTED",
"meeting_personal": false,
"meeting_topic": req.Topic,
Expand All @@ -118,12 +132,12 @@ func (p *Plugin) handleStartMeeting(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), err.StatusCode)
return
} else {
err = p.api.KeyValueStore().Set(fmt.Sprintf("%v%v", POST_MEETING_KEY, meetingId), []byte(post.Id))
err = p.api.KeyValueStore().Set(fmt.Sprintf("%v%v", POST_MEETING_KEY, meetingID), []byte(post.Id))
if err != nil {
http.Error(w, err.Error(), err.StatusCode)
return
}
}

w.Write([]byte(fmt.Sprintf("%v", meetingId)))
w.Write([]byte(fmt.Sprintf("%v", meetingID)))
}
111 changes: 111 additions & 0 deletions server/randomNameGenerator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package main

import (
"math/rand"
"time"
)

var PLURALNOUN = []string{ "Aliens", "Animals", "Antelopes", "Ants", "Apes", "Apples", "Baboons",
"Bacteria", "Badgers", "Bananas", "Bats", "Bears", "Birds", "Bonobos",
"Brides", "Bugs", "Bulls", "Butterflies", "Cheetahs", "Cherries", "Chicken",
"Children", "Chimps", "Clowns", "Cows", "Creatures", "Dinosaurs", "Dogs",
"Dolphins", "Donkeys", "Dragons", "Ducks", "Dwarfs", "Eagles", "Elephants",
"Elves", "Fathers", "Fish", "Flowers", "Frogs", "Fruit", "Fungi",
"Galaxies", "Geese", "Goats", "Gorillas", "Hedgehogs", "Hippos", "Horses",
"Hunters", "Insects", "Kids", "Knights", "Lemons", "Lemurs", "Leopards",
"LifeForms", "Lions", "Lizards", "Mice", "Monkeys", "Monsters", "Mushrooms",
"Octopodes", "Oranges", "Orangutans", "Organisms", "Pants", "Parrots",
"Penguins", "People", "Pigeons", "Pigs", "Pineapples", "Plants", "Potatoes",
"Priests", "Rats", "Reptiles", "Reptilians", "Rhinos", "Seagulls", "Sheep",
"Siblings", "Snakes", "Spaghetti", "Spiders", "Squid", "Squirrels",
"Stars", "Students", "Teachers", "Tigers", "Tomatoes", "Trees", "Vampires",
"Vegetables", "Viruses", "Vulcans", "Weasels", "Werewolves", "Whales",
"Witches", "Wizards", "Wolves", "Workers", "Worms", "Zebras" };

var VERB = []string{ "Abandon", "Adapt", "Advertise", "Answer", "Anticipate", "Appreciate",
"Approach", "Argue", "Ask", "Bite", "Blossom", "Blush", "Breathe", "Breed",
"Bribe", "Burn", "Calculate", "Clean", "Code", "Communicate", "Compute",
"Confess", "Confiscate", "Conjugate", "Conjure", "Consume", "Contemplate",
"Crawl", "Dance", "Delegate", "Devour", "Develop", "Differ", "Discuss",
"Dissolve", "Drink", "Eat", "Elaborate", "Emancipate", "Estimate", "Expire",
"Extinguish", "Extract", "Facilitate", "Fall", "Feed", "Finish", "Floss",
"Fly", "Follow", "Fragment", "Freeze", "Gather", "Glow", "Grow", "Hex",
"Hide", "Hug", "Hurry", "Improve", "Intersect", "Investigate", "Jinx",
"Joke", "Jubilate", "Kiss", "Laugh", "Manage", "Meet", "Merge", "Move",
"Object", "Observe", "Offer", "Paint", "Participate", "Party", "Perform",
"Plan", "Pursue", "Pierce", "Play", "Postpone", "Pray", "Proclaim",
"Question", "Read", "Reckon", "Rejoice", "Represent", "Resize", "Rhyme",
"Scream", "Search", "Select", "Share", "Shoot", "Shout", "Signal", "Sing",
"Skate", "Sleep", "Smile", "Smoke", "Solve", "Spell", "Steer", "Stink",
"Substitute", "Swim", "Taste", "Teach", "Terminate", "Think", "Type",
"Unite", "Vanish", "Worship" };

var ADVERB = []string{ "Absently", "Accurately", "Accusingly", "Adorably", "AllTheTime", "Alone",
"Always", "Amazingly", "Angrily", "Anxiously", "Anywhere", "Appallingly",
"Apparently", "Articulately", "Astonishingly", "Badly", "Barely",
"Beautifully", "Blindly", "Bravely", "Brightly", "Briskly", "Brutally",
"Calmly", "Carefully", "Casually", "Cautiously", "Cleverly", "Constantly",
"Correctly", "Crazily", "Curiously", "Cynically", "Daily", "Dangerously",
"Deliberately", "Delicately", "Desperately", "Discreetly", "Eagerly",
"Easily", "Euphoricly", "Evenly", "Everywhere", "Exactly", "Expectantly",
"Extensively", "Ferociously", "Fiercely", "Finely", "Flatly", "Frequently",
"Frighteningly", "Gently", "Gloriously", "Grimly", "Guiltily", "Happily",
"Hard", "Hastily", "Heroically", "High", "Highly", "Hourly", "Humbly",
"Hysterically", "Immensely", "Impartially", "Impolitely", "Indifferently",
"Intensely", "Jealously", "Jovially", "Kindly", "Lazily", "Lightly",
"Loudly", "Lovingly", "Loyally", "Magnificently", "Malevolently", "Merrily",
"Mightily", "Miserably", "Mysteriously", "NOT", "Nervously", "Nicely",
"Nowhere", "Objectively", "Obnoxiously", "Obsessively", "Obviously",
"Often", "Painfully", "Patiently", "Playfully", "Politely", "Poorly",
"Precisely", "Promptly", "Quickly", "Quietly", "Randomly", "Rapidly",
"Rarely", "Recklessly", "Regularly", "Remorsefully", "Responsibly",
"Rudely", "Ruthlessly", "Sadly", "Scornfully", "Seamlessly", "Seldom",
"Selfishly", "Seriously", "Shakily", "Sharply", "Sideways", "Silently",
"Sleepily", "Slightly", "Slowly", "Slyly", "Smoothly", "Softly", "Solemnly",
"Steadily", "Sternly", "Strangely", "Strongly", "Stunningly", "Surely",
"Tenderly", "Thoughtfully", "Tightly", "Uneasily", "Vanishingly",
"Violently", "Warmly", "Weakly", "Wearily", "Weekly", "Weirdly", "Well",
"Well", "Wickedly", "Wildly", "Wisely", "Wonderfully", "Yearly" };

var ADJECTIVE = []string{ "Abominable", "Accurate", "Adorable", "All", "Alleged", "Ancient", "Angry",
"Anxious", "Appalling", "Apparent", "Astonishing", "Attractive", "Awesome",
"Baby", "Bad", "Beautiful", "Benign", "Big", "Bitter", "Blind", "Blue",
"Bold", "Brave", "Bright", "Brisk", "Calm", "Camouflaged", "Casual",
"Cautious", "Choppy", "Chosen", "Clever", "Cold", "Cool", "Crawly",
"Crazy", "Creepy", "Cruel", "Curious", "Cynical", "Dangerous", "Dark",
"Delicate", "Desperate", "Difficult", "Discreet", "Disguised", "Dizzy",
"Dumb", "Eager", "Easy", "Edgy", "Electric", "Elegant", "Emancipated",
"Enormous", "Euphoric", "Evil", "Fast", "Ferocious", "Fierce", "Fine",
"Flawed", "Flying", "Foolish", "Foxy", "Freezing", "Funny", "Furious",
"Gentle", "Glorious", "Golden", "Good", "Green", "Green", "Guilty",
"Hairy", "Happy", "Hard", "Hasty", "Hazy", "Heroic", "Hostile", "Hot",
"Humble", "Humongous", "Humorous", "Hysterical", "Idealistic", "Ignorant",
"Immense", "Impartial", "Impolite", "Indifferent", "Infuriated",
"Insightful", "Intense", "Interesting", "Intimidated", "Intriguing",
"Jealous", "Jolly", "Jovial", "Jumpy", "Kind", "Laughing", "Lazy", "Liquid",
"Lonely", "Longing", "Loud", "Loving", "Loyal", "Macabre", "Mad", "Magical",
"Magnificent", "Malevolent", "Medieval", "Memorable", "Mere", "Merry",
"Mighty", "Mischievous", "Miserable", "Modified", "Moody", "Most",
"Mysterious", "Mystical", "Needy", "Nervous", "Nice", "Objective",
"Obnoxious", "Obsessive", "Obvious", "Opinionated", "Orange", "Painful",
"Passionate", "Perfect", "Pink", "Playful", "Poisonous", "Polite", "Poor",
"Popular", "Powerful", "Precise", "Preserved", "Pretty", "Purple", "Quick",
"Quiet", "Random", "Rapid", "Rare", "Real", "Reassuring", "Reckless", "Red",
"Regular", "Remorseful", "Responsible", "Rich", "Rude", "Ruthless", "Sad",
"Scared", "Scary", "Scornful", "Screaming", "Selfish", "Serious", "Shady",
"Shaky", "Sharp", "Shiny", "Shy", "Simple", "Sleepy", "Slow", "Sly",
"Small", "Smart", "Smelly", "Smiling", "Smooth", "Smug", "Sober", "Soft",
"Solemn", "Square", "Square", "Steady", "Strange", "Strong", "Stunning",
"Subjective", "Successful", "Surly", "Sweet", "Tactful", "Tense",
"Thoughtful", "Tight", "Tiny", "Tolerant", "Uneasy", "Unique", "Unseen",
"Warm", "Weak", "Weird", "WellCooked", "Wild", "Wise", "Witty", "Wonderful",
"Worried", "Yellow", "Young", "Zealous" };

func randomElement(s []string) string {
rand.Seed(time.Now().UnixNano())
return s[rand.Intn(len(s)-1)]
}

func generateRoomWithoutSeparator() string {
return (randomElement(ADJECTIVE) + randomElement(PLURALNOUN) + randomElement(VERB) + randomElement(ADVERB))
}

0 comments on commit 21761e1

Please sign in to comment.