├── .gitignore ├── .travis.yml ├── DiscordState ├── session.go ├── state.go └── struct.go ├── LICENSE ├── README.md ├── commands.go ├── config.go ├── events.go ├── helper.go ├── main.go ├── menu.go └── screenshot.png /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | *.prof 25 | *.json 26 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | sudo: false 3 | go: 4 | - 1.3 5 | - 1.4 6 | - 1.5 7 | -------------------------------------------------------------------------------- /DiscordState/session.go: -------------------------------------------------------------------------------- 1 | //Package DiscordState is an abstraction layer that gives proper structs and functions to get and set the current state of the cli server 2 | package DiscordState 3 | 4 | import ( 5 | "fmt" 6 | 7 | "github.com/Rivalo/discordgo_cli" 8 | ) 9 | 10 | //!----- Session -----!// 11 | 12 | //NewSession Creates a new Session 13 | func NewSession(Username, Password string) *Session { 14 | Session := new(Session) 15 | Session.Username = Username 16 | Session.Password = Password 17 | 18 | return Session 19 | } 20 | 21 | //Start attaches a discordgo listener to the Sessions and fills it. 22 | func (Session *Session) Start() error { 23 | 24 | fmt.Printf("*Starting Session...") 25 | 26 | dg, err := discordgo.New(Session.Username, Session.Password) 27 | if err != nil { 28 | return err 29 | } 30 | 31 | // Open the websocket and begin listening. 32 | dg.Open() 33 | 34 | //Retrieve GuildID's from current User 35 | UserGuilds, err := dg.UserGuilds() 36 | if err != nil { 37 | return err 38 | } 39 | 40 | Session.Guilds = UserGuilds 41 | 42 | Session.DiscordGo = dg 43 | 44 | Session.User, _ = Session.DiscordGo.User("@me") 45 | 46 | fmt.Printf(" PASSED!\n") 47 | 48 | return nil 49 | } 50 | 51 | //NewState (constructor) attaches a new state to the Guild inside a Session, and fills it. 52 | func (Session *Session) NewState(GuildID string, MessageAmount int) (*State, error) { 53 | State := new(State) 54 | 55 | //Disable Event Handling 56 | State.Enabled = false 57 | 58 | //Set Session 59 | State.Session = Session 60 | 61 | //Set Guild 62 | for _, guildID := range Session.Guilds { 63 | if guildID.ID == GuildID { 64 | Guild, err := State.Session.DiscordGo.Guild(guildID.ID) 65 | if err != nil { 66 | return nil, err 67 | } 68 | 69 | State.Guild = Guild 70 | } 71 | } 72 | 73 | //Retrieve Members 74 | 75 | State.Members = make(map[string]*discordgo.Member) 76 | 77 | for _, Member := range State.Guild.Members { 78 | State.Members[Member.User.Username] = Member 79 | } 80 | 81 | //RetrieveMemberRoles 82 | State.MemberRole = make(map[string]*discordgo.Role) 83 | 84 | for _, Member := range State.Guild.Members { 85 | var MemberRole string 86 | 87 | if len(Member.Roles) > 0 { 88 | MemberRole = Member.Roles[0] 89 | } else { 90 | break 91 | } 92 | 93 | for _, Role := range State.Guild.Roles { 94 | if Role.ID == MemberRole { 95 | State.MemberRole[Member.User.Username] = Role 96 | break 97 | } 98 | } 99 | } 100 | 101 | //Set MessageAmount 102 | State.MessageAmount = MessageAmount 103 | 104 | //Init Messages 105 | State.Messages = []*discordgo.Message{} 106 | 107 | //Retrieve Channels 108 | 109 | State.Channels = State.Guild.Channels 110 | 111 | return State, nil 112 | } 113 | 114 | //Update updates the session, this reloads the Guild list 115 | func (Session *Session) Update() error { 116 | UserGuilds, err := Session.DiscordGo.UserGuilds() 117 | if err != nil { 118 | return err 119 | } 120 | 121 | Session.Guilds = UserGuilds 122 | return nil 123 | } 124 | -------------------------------------------------------------------------------- /DiscordState/state.go: -------------------------------------------------------------------------------- 1 | package DiscordState 2 | 3 | import "github.com/Rivalo/discordgo_cli" 4 | 5 | //SetChannel sets the channel of the current State 6 | func (State *State) SetChannel(ID string) { 7 | for _, Channel := range State.Channels { 8 | if Channel.ID == ID { 9 | State.Channel = Channel 10 | } 11 | } 12 | } 13 | 14 | //AddMember adds Member to State 15 | func (State *State) AddMember(Member *discordgo.Member) { 16 | State.Members[Member.User.ID] = Member 17 | } 18 | 19 | //DelMember deletes Member from State 20 | func (State *State) DelMember(Member *discordgo.Member) { 21 | delete(State.Members, Member.User.ID) 22 | } 23 | 24 | //AddMessage adds Message to State 25 | func (State *State) AddMessage(Message *discordgo.Message) { 26 | //Do not add if Amount <= 0 27 | if State.MessageAmount <= 0 { 28 | return 29 | } 30 | 31 | //Remove First Message if next message is going to increase length past MessageAmount 32 | if len(State.Messages) == State.MessageAmount { 33 | State.Messages = append(State.Messages[:0], State.Messages[1:]...) 34 | } 35 | 36 | State.Messages = append(State.Messages, Message) 37 | } 38 | 39 | //EditMessage edits Message inside State 40 | func (State *State) EditMessage(Message *discordgo.Message) { 41 | for Index, StateMessage := range State.Messages { 42 | if StateMessage.ID == Message.ID { 43 | State.Messages[Index] = Message 44 | } 45 | } 46 | } 47 | 48 | //DelMessage deletes Message from State 49 | func (State *State) DelMessage(Message *discordgo.Message) { 50 | for Index, StateMessage := range State.Messages { 51 | if StateMessage.ID == Message.ID { 52 | State.Messages = append(State.Messages[:Index], State.Messages[Index+1:]...) 53 | } 54 | } 55 | } 56 | 57 | //RetrieveMessages retrieves last N Messages and puts it in state 58 | func (State *State) RetrieveMessages(Amount int) error { 59 | Messages, err := State.Session.DiscordGo.ChannelMessages(State.Channel.ID, Amount, "", "") 60 | if err != nil { 61 | return err 62 | } 63 | 64 | //Reverse insert Messages 65 | for i := 0; i < len(Messages); i++ { 66 | State.AddMessage(Messages[len(Messages)-i-1]) 67 | } 68 | 69 | return nil 70 | } 71 | -------------------------------------------------------------------------------- /DiscordState/struct.go: -------------------------------------------------------------------------------- 1 | package DiscordState 2 | 3 | import "github.com/Rivalo/discordgo_cli" 4 | 5 | //State is the current state of the attached client 6 | type State struct { 7 | Guild *discordgo.Guild 8 | Channel *discordgo.Channel 9 | Channels []*discordgo.Channel 10 | Members map[string]*discordgo.Member 11 | MemberRole map[string]*discordgo.Role 12 | Messages []*discordgo.Message 13 | Session *Session 14 | MessageAmount int //Amount of Messages to keep in State 15 | Enabled bool //Toggles State for Event handling 16 | } 17 | 18 | //Session contains the 'state' of the attached server 19 | type Session struct { 20 | Username string 21 | User *discordgo.User 22 | Password string 23 | DiscordGo *discordgo.Session 24 | Guilds []*discordgo.Guild 25 | } 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # discord-cli 2 | ## Project is on hold 3 | This project was started as an experiment for me to get familiar with Go. Back in the day the Discord API was also a bit simpler and Linux support was not really there unfortunately. Since then Linux support is there luckily, new features have been added to Discord that are not being supported by the cli currently. 4 | I've personally moved on to other things, and since I do not really need a Discord CLI I will not be actively developing the client anymore. 5 | 6 | If people feel like they want to actually manage the project and actively develop for it then contact me. Otherwise if you have an addition that improves the client, please do a pull request. I will look at it. If there are any big problems for further feature development such as API breaks, you can also contact me and we will look if anything can still be done :) 7 | ______ 8 | 9 | Minimalistic Command-Line Interface for Discord 10 | 11 | Master (Semi-Stable): [![Build Status](https://travis-ci.org/Rivalo/discord-cli.svg?branch=master)](https://travis-ci.org/Rivalo/discord-cli), Develop (Default Git Branch): [![Build Status](https://travis-ci.org/Rivalo/discord-cli.svg?branch=develop)](https://travis-ci.org/Rivalo/discord-cli) 12 | 13 | Join our Discord Chat! https://discord.gg/0pXWCo5RQbVuFHDM 14 | 15 | ![I suck at English, while 256 colors is enough for everyone](screenshot.png) 16 | 17 | Disclaimer: Currently only tested on Linux. 18 | 19 | ### How to Install the Master branch? 20 | Currently the easiest working way to install is to use the Go tools. I'm looking at using GCCGO and makefiles to reduce installation steps, and make setting PATHS unnecessary. 21 | * Install the Go Tools and setup the `$GOPATH` (There are loads of tutorial for this part) 22 | * `$ go get -u github.com/Rivalo/discord-cli` 23 | * Go to the `bin` folder inside your `$GOPATH` 24 | * `./discord-cli` 25 | 26 | For trying the develop branch, do a git checkout and reinstall the application. 27 | 28 | ### (Master) Configuration Settings 29 | Configuration files are being stored in JSON format and are automatically created when you first run discord-cli. Do not change the 'key' value inside `{"key":"value"}`, this is the part that discord-cli uses for parsing, missing keys will definitely return errors. 30 | 31 | | Setting | Function | 32 | | ------------- |-------------| 33 | | username | Discord Username (emailaddress) | 34 | | password | Discord Password | 35 | | messagedefault| (true or false) Display messages automatically| 36 | | messages | Amount of Messages kept in memory | 37 | 38 | NOTE: The Configuration settings are likely to change. Breaking updates are stated in the release section. To solve problems, delete `~/.config/discord-cli/config.json` and restart discord-cli. 39 | 40 | ### (Master) Chat Commands 41 | When inside a text channel, the following commands are available: 42 | 43 | | Command | Function | 44 | | ------------- |-------------| 45 | | :q | Quits discord-cli | 46 | | :g | Change listening Guild| 47 | | :c | Change listening Channel inside Guild | 48 | | :m [n] | Display last [n] messages: ex. `:m 2` displays last two messages | 49 | -------------------------------------------------------------------------------- /commands.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "strconv" 5 | "strings" 6 | ) 7 | 8 | //ParseForCommands parses input for Commands, returns message if no command specified, else return is empty 9 | func ParseForCommands(line string) string { 10 | //One Key Commands 11 | switch line { 12 | case ":g": 13 | SelectGuild() 14 | line = "" 15 | case ":c": 16 | SelectChannel() 17 | line = "" 18 | default: 19 | // Nothing 20 | } 21 | 22 | //Argument Commands 23 | if strings.HasPrefix(line, ":m") { 24 | AmountStr := strings.Split(line, " ") 25 | if len(AmountStr) < 2 { 26 | Msg(ErrorMsg, "[:m] No Arguments \n") 27 | return "" 28 | } 29 | 30 | Amount, err := strconv.Atoi(AmountStr[1]) 31 | if err != nil { 32 | Msg(ErrorMsg, "[:m] Argument Error: %s \n", err) 33 | return "" 34 | } 35 | 36 | Msg(InfoMsg, "Printing last %d messages!\n", Amount) 37 | State.RetrieveMessages(Amount) 38 | PrintMessages(Amount) 39 | line = "" 40 | } 41 | 42 | return line 43 | } 44 | 45 | //SelectGuild selects a new Guild 46 | func SelectGuild() { 47 | State.Enabled = false 48 | SelectGuildMenu() 49 | SelectChannelMenu() 50 | State.Enabled = true 51 | ShowContent() 52 | } 53 | 54 | //SelectChannel selects a new Channel 55 | func SelectChannel() { 56 | State.Enabled = false 57 | SelectChannelMenu() 58 | State.Enabled = true 59 | ShowContent() 60 | } 61 | -------------------------------------------------------------------------------- /config.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "log" 6 | "os" 7 | "os/user" 8 | ) 9 | 10 | //Configuration is a struct that contains all configuration fields 11 | type Configuration struct { 12 | Username string `json:"username"` 13 | Password string `json:"password"` 14 | MessageDefault bool `json:"messagedefault"` 15 | Messages int `json:"messages"` 16 | } 17 | 18 | // Config is the global configuration of discord-cli 19 | var Config Configuration 20 | 21 | //GetConfig retrieves configuration file from ~./config/discord-cli, if it doesn't exist it calls CreateConfig() 22 | func GetConfig() { 23 | //Get User 24 | usr, err := user.Current() 25 | if err != nil { 26 | log.Fatal(err) 27 | } 28 | 29 | //Get File 30 | file, err := os.Open(usr.HomeDir + "/.config/discord-cli/config.json") 31 | if err != nil { 32 | log.Println(err) 33 | CreateConfig() 34 | log.Fatalln("Created new config file, please edit contents!") 35 | } 36 | 37 | //Decode File 38 | decoder := json.NewDecoder(file) 39 | err = decoder.Decode(&Config) 40 | if err != nil { 41 | log.Println("Failed to decode configuration file") 42 | log.Fatalf("Error: %s", err) 43 | } 44 | } 45 | 46 | //CreateConfig creates folder inside $HOME and makes a new empty configuration file 47 | func CreateConfig() { 48 | //Get User 49 | usr, err := user.Current() 50 | if err != nil { 51 | log.Fatal(err) 52 | } 53 | 54 | var EmptyStruct Configuration 55 | //Set Default values 56 | EmptyStruct.Messages = 10 57 | EmptyStruct.MessageDefault = true 58 | 59 | //Create Folder 60 | err = os.MkdirAll(usr.HomeDir+"/.config/discord-cli/", os.ModePerm) 61 | if err != nil { 62 | log.Fatalln(err) 63 | } 64 | 65 | //Create File 66 | file, err := os.Create(usr.HomeDir + "/.config/discord-cli/config.json") 67 | if err != nil { 68 | log.Fatalln(err) 69 | } 70 | 71 | //Marshall EmptyStruct 72 | raw, err := json.Marshal(EmptyStruct) 73 | if err != nil { 74 | log.Fatalln(err) 75 | } 76 | 77 | //PrintToFile 78 | _, err = file.Write(raw) 79 | if err != nil { 80 | log.Fatalln(err) 81 | } 82 | 83 | file.Close() 84 | } 85 | 86 | //CheckState checks the current state for essential missing information, errors will fail the program 87 | func CheckState() { 88 | //Get User 89 | usr, err := user.Current() 90 | if err != nil { 91 | log.Fatal(err) 92 | } 93 | 94 | if Config.Username == "" { 95 | log.Fatalln("No Username Specified, please edit " + usr.HomeDir + "/.config/discord-cli/config.json") 96 | } 97 | 98 | if Config.Password == "" { 99 | log.Fatalln("No Password Specified, please edit " + usr.HomeDir + "/.config/discord-cli/config.json") 100 | } 101 | 102 | } 103 | -------------------------------------------------------------------------------- /events.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/Rivalo/discordgo_cli" 7 | ) 8 | 9 | // This function will be called (due to AddHandler above) every time a new 10 | // message is created on any channel that the autenticated user has access to. 11 | func newMessage(s *discordgo.Session, m *discordgo.MessageCreate) { 12 | //Global Mentions 13 | Mention := "@" + State.Session.User.Username 14 | if strings.Contains(m.ContentWithMentionsReplaced(), Mention) { 15 | go Notify(m.Message) 16 | } 17 | 18 | // Do nothing when State is disabled 19 | if !State.Enabled { 20 | return 21 | } 22 | 23 | //State Messages 24 | if m.ChannelID == State.Channel.ID { 25 | State.AddMessage(m.Message) 26 | 27 | Messages := ReceivingMessageParser(m.Message) 28 | 29 | for _, Msg := range Messages { 30 | MessagePrint(m.Timestamp, m.Author.Username, Msg) 31 | //log.Printf("> %s > %s\n", UserName(m.Author.Username), Msg) 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /helper.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/binary" 5 | "log" 6 | "math" 7 | "os" 8 | "os/exec" 9 | "strings" 10 | "time" 11 | 12 | "github.com/Rivalo/discordgo_cli" 13 | "github.com/fatih/color" 14 | ) 15 | 16 | //HexColor is a struct gives RGB values 17 | type HexColor struct { 18 | Color color.Attribute 19 | R int 20 | G int 21 | B int 22 | } 23 | 24 | //Msg is a composition of Color.New printf functions 25 | func Msg(MsgType, format string, a ...interface{}) { 26 | 27 | // TODO: Add support for changing color by configuration 28 | 29 | Error := color.New(color.FgRed, color.Bold) 30 | Info := color.New(color.FgYellow, color.Bold) 31 | Head := color.New(color.FgCyan, color.Bold) 32 | Text := color.New(color.FgWhite) 33 | 34 | switch MsgType { 35 | case "Error": 36 | Error.Printf(format, a...) 37 | case "Info": 38 | Info.Printf(format, a...) 39 | case "Head": 40 | Head.Printf(format, a...) 41 | case "Text": 42 | Text.Printf(format, a...) 43 | default: 44 | Text.Printf(format, a...) 45 | } 46 | } 47 | 48 | //Clear clears the terminal => This barely works, please fix 49 | func Clear() { 50 | 51 | // TODO: ADD support for multiple operating systems and terminals. Linux = clear, Windows = cls, have to do research for OSX and BSD. 52 | 53 | c := exec.Command("clear") 54 | c.Stdout = os.Stdout 55 | c.Run() 56 | } 57 | 58 | //Header simply prints a header containing state/session information 59 | func Header() { 60 | Msg(InfoMsg, "Welcome, %s!\n\n", State.Session.User.Username) 61 | Msg(InfoMsg, "Guild: %s, Channel: %s\n", State.Guild.Name, State.Channel.Name) 62 | } 63 | 64 | //ReceivingMessageParser parses receiving message for mentions, images and MultiLine and returns string array 65 | func ReceivingMessageParser(m *discordgo.Message) []string { 66 | Message := m.ContentWithMentionsReplaced() 67 | 68 | //Parse images 69 | for _, Attachment := range m.Attachments { 70 | Message = Message + " " + Attachment.URL 71 | } 72 | 73 | // MultiLine comment parsing 74 | Messages := strings.Split(Message, "\n") 75 | 76 | return Messages 77 | } 78 | 79 | //PrintMessages prints amount of Messages to CLI 80 | func PrintMessages(Amount int) { 81 | for Key, m := range State.Messages { 82 | if Key >= len(State.Messages)-Amount { 83 | Messages := ReceivingMessageParser(m) 84 | 85 | for _, Msg := range Messages { 86 | //log.Printf("> %s > %s\n", UserName(m.Author.Username), Msg) 87 | MessagePrint(m.Timestamp, m.Author.Username, Msg) 88 | 89 | } 90 | } 91 | } 92 | } 93 | 94 | //Notify uses Notify-Send from libnotify to send a notification when a mention arrives. 95 | func Notify(m *discordgo.Message) { 96 | Channel, err := State.Session.DiscordGo.Channel(m.ChannelID) 97 | if err != nil { 98 | Msg(ErrorMsg, "(NOT) Channel Error: %s\n", err) 99 | } 100 | Guild, err := State.Session.DiscordGo.Guild(Channel.GuildID) 101 | if err != nil { 102 | Msg(ErrorMsg, "(NOT) Guild Error: %s\n", err) 103 | } 104 | Title := "@" + m.Author.Username + " : " + Guild.Name + "/" + Channel.Name 105 | cmd := exec.Command("notify-send", Title, m.ContentWithMentionsReplaced()) 106 | err = cmd.Start() 107 | if err != nil { 108 | Msg(ErrorMsg, "(NOT) Check if libnotify is installed, or disable notifications.\n") 109 | } 110 | 111 | } 112 | 113 | //MessagePrint prints one correctly formatted Message to stdout 114 | func MessagePrint(Time, Username, Content string) { 115 | var Color color.Attribute 116 | TimeStamp, _ := time.Parse(time.RFC3339, Time) 117 | LocalTime := TimeStamp.Local().Format("2006/01/02 15:04:05") 118 | if val, ok := State.MemberRole[Username]; ok { 119 | Color = ColorMatch(val.Color) 120 | } 121 | UserName := color.New(Color).SprintFunc() 122 | 123 | log.SetFlags(0) 124 | log.Printf("%s > %s > %s\n", LocalTime, UserName(Username), Content) 125 | log.SetFlags(log.LstdFlags) 126 | } 127 | 128 | //ColorMatch compares HEX->DEC colorcoding and returns the closest ANSI color 129 | func ColorMatch(colorinput int) color.Attribute { 130 | var Result float64 131 | var ColorResult color.Attribute 132 | Result = 10000 133 | 134 | log.Println(colorinput) 135 | 136 | var ANSIColors []HexColor 137 | ANSIColors = append(ANSIColors, HexColor{color.FgRed, 255, 0, 0}) 138 | ANSIColors = append(ANSIColors, HexColor{color.FgGreen, 0, 128, 0}) 139 | ANSIColors = append(ANSIColors, HexColor{color.FgYellow, 255, 255, 0}) 140 | ANSIColors = append(ANSIColors, HexColor{color.FgBlue, 0, 0, 255}) 141 | ANSIColors = append(ANSIColors, HexColor{color.FgMagenta, 255, 0, 255}) 142 | ANSIColors = append(ANSIColors, HexColor{color.FgCyan, 0, 255, 255}) 143 | ANSIColors = append(ANSIColors, HexColor{color.FgWhite, 255, 255, 255}) 144 | HexNumber := [4]byte{} 145 | binary.BigEndian.PutUint32(HexNumber[:], uint32(colorinput)) 146 | InputStruct := HexColor{color.FgBlack, int(HexNumber[1]), int(HexNumber[2]), int(HexNumber[3])} 147 | 148 | for _, acolor := range ANSIColors { 149 | DiffSum := dis(acolor.R, InputStruct.R) + dis(acolor.G, InputStruct.G) + dis(acolor.B, InputStruct.B) 150 | TestResult := math.Sqrt(DiffSum) 151 | if TestResult < Result { 152 | Result = TestResult 153 | ColorResult = acolor.Color 154 | } 155 | } 156 | 157 | return ColorResult 158 | } 159 | 160 | func dis(a, b int) float64 { 161 | return float64((a - b) * (a - b)) 162 | } 163 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | // This file provides a basic "quick start" example of using the Discordgo 2 | // package to connect to Discord using the New() helper function. 3 | package main 4 | 5 | import ( 6 | "log" 7 | "regexp" 8 | 9 | "github.com/Rivalo/discord-cli/DiscordState" 10 | "github.com/chzyer/readline" 11 | ) 12 | 13 | //Global Message Types 14 | const ( 15 | ErrorMsg = "Error" 16 | InfoMsg = "Info" 17 | HeaderMsg = "Head" 18 | TextMsg = "Text" 19 | ) 20 | 21 | //Version is current version const 22 | const Version = "v0.3.0-DEVELOP" 23 | 24 | //Session is global Session 25 | var Session *DiscordState.Session 26 | 27 | //State is global State 28 | var State *DiscordState.State 29 | 30 | //MsgType is a string containing global message type 31 | type MsgType string 32 | 33 | func main() { 34 | //Initialize Config 35 | GetConfig() 36 | CheckState() 37 | Clear() 38 | Msg(HeaderMsg, "discord-cli - version: %s\n\n", Version) 39 | 40 | //NewSession 41 | Session = DiscordState.NewSession(Config.Username, Config.Password) //Please don't abuse 42 | err := Session.Start() 43 | if err != nil { 44 | log.Println("Session Failed") 45 | log.Fatalln(err) 46 | } 47 | 48 | //Attach New Window 49 | InitWindow() 50 | 51 | //Attach Even Handlers 52 | State.Session.DiscordGo.AddHandler(newMessage) 53 | 54 | //Setup Readline 55 | rl, err := readline.NewEx(&readline.Config{ 56 | Prompt: "> ", 57 | UniqueEditLine: true, 58 | }) 59 | 60 | defer rl.Close() 61 | log.SetOutput(rl.Stderr()) // let "log" write to l.Stderr instead of os.Stderr 62 | 63 | //Start Listening 64 | for { 65 | line, _ := rl.Readline() 66 | 67 | //QUIT 68 | if line == ":q" { 69 | break 70 | } 71 | 72 | //Parse Commands 73 | line = ParseForCommands(line) 74 | 75 | line = ParseForMentions(line) 76 | 77 | if line != "" { 78 | State.Session.DiscordGo.ChannelMessageSend(State.Channel.ID, line) 79 | } 80 | } 81 | 82 | return 83 | } 84 | 85 | //InitWindow creates a New CLI Window 86 | func InitWindow() { 87 | SelectGuildMenu() 88 | SelectChannelMenu() 89 | State.Enabled = true 90 | ShowContent() 91 | } 92 | 93 | //ShowContent shows defaulth Channel content 94 | func ShowContent() { 95 | Clear() 96 | Header() 97 | if Config.MessageDefault { 98 | State.RetrieveMessages(Config.Messages) 99 | PrintMessages(Config.Messages) 100 | } 101 | } 102 | 103 | //ParseForMentions parses input string for mentions 104 | func ParseForMentions(line string) string { 105 | r, err := regexp.Compile("\\@\\w+") 106 | if err != nil { 107 | Msg(ErrorMsg, "Regex Error: ", err) 108 | } 109 | 110 | lineByte := r.ReplaceAllFunc([]byte(line), ReplaceMentions) 111 | 112 | return string(lineByte[:]) 113 | } 114 | 115 | //ReplaceMentions replaces mentions to ID 116 | func ReplaceMentions(input []byte) []byte { 117 | var OutputString string 118 | 119 | SizeByte := len(input) 120 | InputString := string(input[1:SizeByte]) 121 | 122 | if Member, ok := State.Members[InputString]; ok { 123 | OutputString = "<@" + Member.User.ID + ">" 124 | } else { 125 | OutputString = "@" + InputString 126 | } 127 | return []byte(OutputString) 128 | } 129 | -------------------------------------------------------------------------------- /menu.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "strconv" 7 | ) 8 | 9 | //SelectGuildMenu is a menu item that creates a new State on basis of Guild selection 10 | func SelectGuildMenu() { 11 | var err error 12 | 13 | Start: 14 | 15 | Msg(InfoMsg, "Select a Guild:\n") 16 | 17 | SelectMap := make(map[int]string) 18 | SelectID := 0 19 | 20 | for _, guild := range Session.Guilds { 21 | SelectMap[SelectID] = guild.ID 22 | Msg(TextMsg, "[%d] %s\n", SelectID, guild.Name) 23 | SelectID++ 24 | } 25 | Msg(TextMsg, "[b] Extra Options\n") 26 | 27 | var response string 28 | fmt.Scanf("%s\n", &response) 29 | 30 | if response == "b" { 31 | ExtraGuildMenuOptions() 32 | goto Start 33 | } 34 | 35 | ResponseInteger, err := strconv.Atoi(response) 36 | if err != nil { 37 | Msg(ErrorMsg, "(GU) Conversion Error: %s\n", err) 38 | goto Start 39 | } 40 | 41 | if ResponseInteger > SelectID-1 || ResponseInteger < 0 { 42 | Msg(ErrorMsg, "(GU) Error: ID is out of bounds\n") 43 | goto Start 44 | } 45 | 46 | State, err = Session.NewState(SelectMap[ResponseInteger], Config.Messages) 47 | if err != nil { 48 | log.Fatal(err) 49 | } 50 | } 51 | 52 | //SelectChannelMenu is a menu item that sets the current channel 53 | func SelectChannelMenu() { 54 | Start: 55 | Msg(InfoMsg, "Select a Channel:\n") 56 | 57 | SelectMap := make(map[int]string) 58 | SelectID := 0 59 | 60 | for _, channel := range State.Channels { 61 | if channel.Type == "text" { 62 | SelectMap[SelectID] = channel.ID 63 | Msg(TextMsg, "[%d] %s\n", SelectID, channel.Name) 64 | SelectID++ 65 | } 66 | } 67 | Msg(TextMsg, "[b] Go Back\n") 68 | 69 | var response string 70 | fmt.Scanf("%s\n", &response) 71 | 72 | if response == "b" { 73 | SelectGuildMenu() 74 | goto Start 75 | } 76 | 77 | ResponseInteger, err := strconv.Atoi(response) 78 | if err != nil { 79 | Msg(ErrorMsg, "(CH) Conversion Error: %s\n", err) 80 | goto Start 81 | } 82 | 83 | if ResponseInteger > SelectID-1 || ResponseInteger < 0 { 84 | Msg(ErrorMsg, "(CH) Error: ID is out of bound\n") 85 | goto Start 86 | } 87 | 88 | State.SetChannel(SelectMap[ResponseInteger]) 89 | } 90 | 91 | //ExtraGuildMenuOptions prints and handles extra options for SelectGuildMenu 92 | func ExtraGuildMenuOptions() { 93 | Start: 94 | Msg(InfoMsg, "Extra Options:\n") 95 | Msg(TextMsg, "[n] Join New Server\n") 96 | Msg(TextMsg, "[d] Leave Server\n") 97 | Msg(TextMsg, "[o] Join Official discord-cli Server\n") 98 | Msg(TextMsg, "[b] Go Back\n") 99 | 100 | var response string 101 | fmt.Scanf("%s\n", &response) 102 | 103 | switch response { 104 | case "n": 105 | New: 106 | Msg(TextMsg, "Please input invite number ([b] back):\n") 107 | fmt.Scanf("%s\n", &response) 108 | if response == "b" { 109 | goto Start 110 | } 111 | Invite, err := Session.DiscordGo.Invite(response) 112 | if err != nil { 113 | Msg(ErrorMsg, "Invalid Invite\n") 114 | goto New 115 | } 116 | Msg(TextMsg, "Join %s ? [y/n]:\n", Invite.Guild.Name) 117 | fmt.Scanf("%s\n", &response) 118 | if response == "y" { 119 | Session.DiscordGo.InviteAccept(Invite.Code) 120 | err := Session.Update() 121 | if err != nil { 122 | Msg(ErrorMsg, "Session Update Failed: %s\n", err) 123 | } 124 | } else { 125 | goto Start 126 | } 127 | case "o": 128 | _, err := Session.DiscordGo.InviteAccept("0pXWCo5RQbVuFHDM") 129 | if err != nil { 130 | Msg(ErrorMsg, "Joining Official discord-cli Server failed\n") 131 | goto Start 132 | } 133 | Msg(InfoMsg, "Joined Official discord-cli Server!\n") 134 | case "d": 135 | LeaveServerMenu() 136 | goto Start 137 | default: 138 | return 139 | } 140 | 141 | return 142 | } 143 | 144 | //LeaveServerMenu is a copy of SelectGuildMenu that leaves instead of selects 145 | func LeaveServerMenu() { 146 | var err error 147 | 148 | Start: 149 | 150 | Msg(InfoMsg, "Leave a Guild:\n") 151 | 152 | SelectMap := make(map[int]string) 153 | SelectID := 0 154 | 155 | for _, guild := range Session.Guilds { 156 | SelectMap[SelectID] = guild.ID 157 | Msg(TextMsg, "[%d] %s\n", SelectID, guild.Name) 158 | SelectID++ 159 | } 160 | Msg(TextMsg, "[b] Go Back\n") 161 | 162 | var response string 163 | fmt.Scanf("%s\n", &response) 164 | 165 | if response == "b" { 166 | return 167 | } 168 | 169 | ResponseInteger, err := strconv.Atoi(response) 170 | if err != nil { 171 | Msg(ErrorMsg, "(GUD) Conversion Error: %s\n", err) 172 | goto Start 173 | } 174 | 175 | if ResponseInteger > SelectID-1 || ResponseInteger < 0 { 176 | Msg(ErrorMsg, "(GUD) Error: ID is out of bounds\n") 177 | goto Start 178 | } 179 | 180 | Guild, err := Session.DiscordGo.Guild(SelectMap[ResponseInteger]) 181 | if err != nil { 182 | Msg(ErrorMsg, "(GUD) Unknown Error: %s\n", err) 183 | goto Start 184 | } 185 | 186 | Msg(TextMsg, "Leave %s ? [y/n]:\n", Guild.Name) 187 | fmt.Scanf("%s\n", &response) 188 | if response == "y" { 189 | Session.DiscordGo.GuildLeave(Guild.ID) 190 | err := Session.Update() 191 | if err != nil { 192 | Msg(ErrorMsg, "Session Update Failed: %s\n", err) 193 | } 194 | } else { 195 | goto Start 196 | } 197 | 198 | } 199 | -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RickvanLoo/discord-cli/fe746bddc99c0c1633947145cee2b9e1925a3280/screenshot.png --------------------------------------------------------------------------------