Skip to content

Commit 21761e1

Browse files
author
Sean Sackowitz
committed
Random room names, Topic specific room name
Added randomNameGenerator sourced from Jitsi, and converted to Go. This gives more creative, and unique room names.
1 parent 8c249bb commit 21761e1

File tree

4 files changed

+137
-11
lines changed

4 files changed

+137
-11
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# Build
1717
/coverage.txt
1818
/plugin.exe
19-
/mattermost-zoom-plugin*.tar.gz
19+
/mattermost-jitsi-plugin*.tar.gz
2020
/dist
2121
server/vendor
2222
node_modules
@@ -26,3 +26,4 @@ webapp/dist
2626
# Mac
2727
*.swp
2828
.DS_Store
29+
package-lock.json

plugin.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"id": "jitsi",
33
"name": "Jitsi",
4-
"description": "Jitsi audio and video conferencing plugin for Mattermost.",
5-
"version": "0.1.1",
4+
"description": "Jitsi audio and video conferencing plugin for Mattermost. Follow https://github.com/seansackowitz/mattermost-plugin-jitsi for notifications on updates.",
5+
"version": "0.2.0",
66
"backend": {
77
"executable": "server/plugin.exe"
88
},

server/plugin.go

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package main
33
import (
44
"encoding/json"
55
"fmt"
6+
"log"
67
"net/http"
8+
"regexp"
79
"strings"
810
"sync/atomic"
911

@@ -67,6 +69,14 @@ type StartMeetingRequest struct {
6769
MeetingId int `json:"meeting_id"`
6870
}
6971

72+
func encodeJitsiMeetingID(meeting string) string {
73+
reg, err := regexp.Compile("[^a-zA-Z0-9]+")
74+
if err != nil {
75+
log.Fatal(err)
76+
}
77+
return reg.ReplaceAllString(meeting, "")
78+
}
79+
7080
func (p *Plugin) handleStartMeeting(w http.ResponseWriter, r *http.Request) {
7181
userId := r.Header.Get("Mattermost-User-Id")
7282

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

96-
meetingId := userId + req.ChannelId
97-
jitsiUrl := strings.TrimSpace(p.config().JitsiURL)
98-
meetingUrl := jitsiUrl + "/" + meetingId
106+
var meetingID string
107+
meetingID = encodeJitsiMeetingID(req.Topic)
108+
if len(req.Topic) < 1 {
109+
meetingID = generateRoomWithoutSeparator()
110+
}
111+
jitsiURL := strings.TrimSpace(p.config().JitsiURL)
112+
meetingURL := jitsiURL + "/" + meetingID
99113

100114
post := &model.Post{
101115
UserId: user.Id,
102116
ChannelId: req.ChannelId,
103-
Message: fmt.Sprintf("Meeting started at %s.", meetingUrl),
117+
Message: fmt.Sprintf("Meeting started at %s.", meetingURL),
104118
Type: "custom_zoom",
105119
Props: map[string]interface{}{
106-
"meeting_id": meetingId,
107-
"meeting_link": meetingUrl,
120+
"meeting_id": meetingID,
121+
"meeting_link": meetingURL,
108122
"meeting_status": "STARTED",
109123
"meeting_personal": false,
110124
"meeting_topic": req.Topic,
@@ -118,12 +132,12 @@ func (p *Plugin) handleStartMeeting(w http.ResponseWriter, r *http.Request) {
118132
http.Error(w, err.Error(), err.StatusCode)
119133
return
120134
} else {
121-
err = p.api.KeyValueStore().Set(fmt.Sprintf("%v%v", POST_MEETING_KEY, meetingId), []byte(post.Id))
135+
err = p.api.KeyValueStore().Set(fmt.Sprintf("%v%v", POST_MEETING_KEY, meetingID), []byte(post.Id))
122136
if err != nil {
123137
http.Error(w, err.Error(), err.StatusCode)
124138
return
125139
}
126140
}
127141

128-
w.Write([]byte(fmt.Sprintf("%v", meetingId)))
142+
w.Write([]byte(fmt.Sprintf("%v", meetingID)))
129143
}

server/randomNameGenerator.go

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
package main
2+
3+
import (
4+
"math/rand"
5+
"time"
6+
)
7+
8+
var PLURALNOUN = []string{ "Aliens", "Animals", "Antelopes", "Ants", "Apes", "Apples", "Baboons",
9+
"Bacteria", "Badgers", "Bananas", "Bats", "Bears", "Birds", "Bonobos",
10+
"Brides", "Bugs", "Bulls", "Butterflies", "Cheetahs", "Cherries", "Chicken",
11+
"Children", "Chimps", "Clowns", "Cows", "Creatures", "Dinosaurs", "Dogs",
12+
"Dolphins", "Donkeys", "Dragons", "Ducks", "Dwarfs", "Eagles", "Elephants",
13+
"Elves", "Fathers", "Fish", "Flowers", "Frogs", "Fruit", "Fungi",
14+
"Galaxies", "Geese", "Goats", "Gorillas", "Hedgehogs", "Hippos", "Horses",
15+
"Hunters", "Insects", "Kids", "Knights", "Lemons", "Lemurs", "Leopards",
16+
"LifeForms", "Lions", "Lizards", "Mice", "Monkeys", "Monsters", "Mushrooms",
17+
"Octopodes", "Oranges", "Orangutans", "Organisms", "Pants", "Parrots",
18+
"Penguins", "People", "Pigeons", "Pigs", "Pineapples", "Plants", "Potatoes",
19+
"Priests", "Rats", "Reptiles", "Reptilians", "Rhinos", "Seagulls", "Sheep",
20+
"Siblings", "Snakes", "Spaghetti", "Spiders", "Squid", "Squirrels",
21+
"Stars", "Students", "Teachers", "Tigers", "Tomatoes", "Trees", "Vampires",
22+
"Vegetables", "Viruses", "Vulcans", "Weasels", "Werewolves", "Whales",
23+
"Witches", "Wizards", "Wolves", "Workers", "Worms", "Zebras" };
24+
25+
var VERB = []string{ "Abandon", "Adapt", "Advertise", "Answer", "Anticipate", "Appreciate",
26+
"Approach", "Argue", "Ask", "Bite", "Blossom", "Blush", "Breathe", "Breed",
27+
"Bribe", "Burn", "Calculate", "Clean", "Code", "Communicate", "Compute",
28+
"Confess", "Confiscate", "Conjugate", "Conjure", "Consume", "Contemplate",
29+
"Crawl", "Dance", "Delegate", "Devour", "Develop", "Differ", "Discuss",
30+
"Dissolve", "Drink", "Eat", "Elaborate", "Emancipate", "Estimate", "Expire",
31+
"Extinguish", "Extract", "Facilitate", "Fall", "Feed", "Finish", "Floss",
32+
"Fly", "Follow", "Fragment", "Freeze", "Gather", "Glow", "Grow", "Hex",
33+
"Hide", "Hug", "Hurry", "Improve", "Intersect", "Investigate", "Jinx",
34+
"Joke", "Jubilate", "Kiss", "Laugh", "Manage", "Meet", "Merge", "Move",
35+
"Object", "Observe", "Offer", "Paint", "Participate", "Party", "Perform",
36+
"Plan", "Pursue", "Pierce", "Play", "Postpone", "Pray", "Proclaim",
37+
"Question", "Read", "Reckon", "Rejoice", "Represent", "Resize", "Rhyme",
38+
"Scream", "Search", "Select", "Share", "Shoot", "Shout", "Signal", "Sing",
39+
"Skate", "Sleep", "Smile", "Smoke", "Solve", "Spell", "Steer", "Stink",
40+
"Substitute", "Swim", "Taste", "Teach", "Terminate", "Think", "Type",
41+
"Unite", "Vanish", "Worship" };
42+
43+
var ADVERB = []string{ "Absently", "Accurately", "Accusingly", "Adorably", "AllTheTime", "Alone",
44+
"Always", "Amazingly", "Angrily", "Anxiously", "Anywhere", "Appallingly",
45+
"Apparently", "Articulately", "Astonishingly", "Badly", "Barely",
46+
"Beautifully", "Blindly", "Bravely", "Brightly", "Briskly", "Brutally",
47+
"Calmly", "Carefully", "Casually", "Cautiously", "Cleverly", "Constantly",
48+
"Correctly", "Crazily", "Curiously", "Cynically", "Daily", "Dangerously",
49+
"Deliberately", "Delicately", "Desperately", "Discreetly", "Eagerly",
50+
"Easily", "Euphoricly", "Evenly", "Everywhere", "Exactly", "Expectantly",
51+
"Extensively", "Ferociously", "Fiercely", "Finely", "Flatly", "Frequently",
52+
"Frighteningly", "Gently", "Gloriously", "Grimly", "Guiltily", "Happily",
53+
"Hard", "Hastily", "Heroically", "High", "Highly", "Hourly", "Humbly",
54+
"Hysterically", "Immensely", "Impartially", "Impolitely", "Indifferently",
55+
"Intensely", "Jealously", "Jovially", "Kindly", "Lazily", "Lightly",
56+
"Loudly", "Lovingly", "Loyally", "Magnificently", "Malevolently", "Merrily",
57+
"Mightily", "Miserably", "Mysteriously", "NOT", "Nervously", "Nicely",
58+
"Nowhere", "Objectively", "Obnoxiously", "Obsessively", "Obviously",
59+
"Often", "Painfully", "Patiently", "Playfully", "Politely", "Poorly",
60+
"Precisely", "Promptly", "Quickly", "Quietly", "Randomly", "Rapidly",
61+
"Rarely", "Recklessly", "Regularly", "Remorsefully", "Responsibly",
62+
"Rudely", "Ruthlessly", "Sadly", "Scornfully", "Seamlessly", "Seldom",
63+
"Selfishly", "Seriously", "Shakily", "Sharply", "Sideways", "Silently",
64+
"Sleepily", "Slightly", "Slowly", "Slyly", "Smoothly", "Softly", "Solemnly",
65+
"Steadily", "Sternly", "Strangely", "Strongly", "Stunningly", "Surely",
66+
"Tenderly", "Thoughtfully", "Tightly", "Uneasily", "Vanishingly",
67+
"Violently", "Warmly", "Weakly", "Wearily", "Weekly", "Weirdly", "Well",
68+
"Well", "Wickedly", "Wildly", "Wisely", "Wonderfully", "Yearly" };
69+
70+
var ADJECTIVE = []string{ "Abominable", "Accurate", "Adorable", "All", "Alleged", "Ancient", "Angry",
71+
"Anxious", "Appalling", "Apparent", "Astonishing", "Attractive", "Awesome",
72+
"Baby", "Bad", "Beautiful", "Benign", "Big", "Bitter", "Blind", "Blue",
73+
"Bold", "Brave", "Bright", "Brisk", "Calm", "Camouflaged", "Casual",
74+
"Cautious", "Choppy", "Chosen", "Clever", "Cold", "Cool", "Crawly",
75+
"Crazy", "Creepy", "Cruel", "Curious", "Cynical", "Dangerous", "Dark",
76+
"Delicate", "Desperate", "Difficult", "Discreet", "Disguised", "Dizzy",
77+
"Dumb", "Eager", "Easy", "Edgy", "Electric", "Elegant", "Emancipated",
78+
"Enormous", "Euphoric", "Evil", "Fast", "Ferocious", "Fierce", "Fine",
79+
"Flawed", "Flying", "Foolish", "Foxy", "Freezing", "Funny", "Furious",
80+
"Gentle", "Glorious", "Golden", "Good", "Green", "Green", "Guilty",
81+
"Hairy", "Happy", "Hard", "Hasty", "Hazy", "Heroic", "Hostile", "Hot",
82+
"Humble", "Humongous", "Humorous", "Hysterical", "Idealistic", "Ignorant",
83+
"Immense", "Impartial", "Impolite", "Indifferent", "Infuriated",
84+
"Insightful", "Intense", "Interesting", "Intimidated", "Intriguing",
85+
"Jealous", "Jolly", "Jovial", "Jumpy", "Kind", "Laughing", "Lazy", "Liquid",
86+
"Lonely", "Longing", "Loud", "Loving", "Loyal", "Macabre", "Mad", "Magical",
87+
"Magnificent", "Malevolent", "Medieval", "Memorable", "Mere", "Merry",
88+
"Mighty", "Mischievous", "Miserable", "Modified", "Moody", "Most",
89+
"Mysterious", "Mystical", "Needy", "Nervous", "Nice", "Objective",
90+
"Obnoxious", "Obsessive", "Obvious", "Opinionated", "Orange", "Painful",
91+
"Passionate", "Perfect", "Pink", "Playful", "Poisonous", "Polite", "Poor",
92+
"Popular", "Powerful", "Precise", "Preserved", "Pretty", "Purple", "Quick",
93+
"Quiet", "Random", "Rapid", "Rare", "Real", "Reassuring", "Reckless", "Red",
94+
"Regular", "Remorseful", "Responsible", "Rich", "Rude", "Ruthless", "Sad",
95+
"Scared", "Scary", "Scornful", "Screaming", "Selfish", "Serious", "Shady",
96+
"Shaky", "Sharp", "Shiny", "Shy", "Simple", "Sleepy", "Slow", "Sly",
97+
"Small", "Smart", "Smelly", "Smiling", "Smooth", "Smug", "Sober", "Soft",
98+
"Solemn", "Square", "Square", "Steady", "Strange", "Strong", "Stunning",
99+
"Subjective", "Successful", "Surly", "Sweet", "Tactful", "Tense",
100+
"Thoughtful", "Tight", "Tiny", "Tolerant", "Uneasy", "Unique", "Unseen",
101+
"Warm", "Weak", "Weird", "WellCooked", "Wild", "Wise", "Witty", "Wonderful",
102+
"Worried", "Yellow", "Young", "Zealous" };
103+
104+
func randomElement(s []string) string {
105+
rand.Seed(time.Now().UnixNano())
106+
return s[rand.Intn(len(s)-1)]
107+
}
108+
109+
func generateRoomWithoutSeparator() string {
110+
return (randomElement(ADJECTIVE) + randomElement(PLURALNOUN) + randomElement(VERB) + randomElement(ADVERB))
111+
}

0 commit comments

Comments
 (0)