repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
mholt/archiver | tar.go | hasTarHeader | func hasTarHeader(buf []byte) bool {
if len(buf) < tarBlockSize {
return false
}
b := buf[148:156]
b = bytes.Trim(b, " \x00") // clean up all spaces and null bytes
if len(b) == 0 {
return false // unknown format
}
hdrSum, err := strconv.ParseUint(string(b), 8, 64)
if err != nil {
return false
}
// Acc... | go | func hasTarHeader(buf []byte) bool {
if len(buf) < tarBlockSize {
return false
}
b := buf[148:156]
b = bytes.Trim(b, " \x00") // clean up all spaces and null bytes
if len(b) == 0 {
return false // unknown format
}
hdrSum, err := strconv.ParseUint(string(b), 8, 64)
if err != nil {
return false
}
// Acc... | [
"func",
"hasTarHeader",
"(",
"buf",
"[",
"]",
"byte",
")",
"bool",
"{",
"if",
"len",
"(",
"buf",
")",
"<",
"tarBlockSize",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"b",
":=",
"buf",
"[",
"148",
":",
"156",
"]",
"\n",
"b",
"=",
"bytes",
".",
"... | // hasTarHeader checks passed bytes has a valid tar header or not. buf must
// contain at least 512 bytes and if not, it always returns false. | [
"hasTarHeader",
"checks",
"passed",
"bytes",
"has",
"a",
"valid",
"tar",
"header",
"or",
"not",
".",
"buf",
"must",
"contain",
"at",
"least",
"512",
"bytes",
"and",
"if",
"not",
"it",
"always",
"returns",
"false",
"."
] | 5e4ca701b6014549de7fa8734b3c7c5caf98af9e | https://github.com/mholt/archiver/blob/5e4ca701b6014549de7fa8734b3c7c5caf98af9e/tar.go#L558-L590 | train |
mholt/archiver | tarlz4.go | Archive | func (tlz4 *TarLz4) Archive(sources []string, destination string) error {
err := tlz4.CheckExt(destination)
if err != nil {
return fmt.Errorf("output %s", err.Error())
}
tlz4.wrapWriter()
return tlz4.Tar.Archive(sources, destination)
} | go | func (tlz4 *TarLz4) Archive(sources []string, destination string) error {
err := tlz4.CheckExt(destination)
if err != nil {
return fmt.Errorf("output %s", err.Error())
}
tlz4.wrapWriter()
return tlz4.Tar.Archive(sources, destination)
} | [
"func",
"(",
"tlz4",
"*",
"TarLz4",
")",
"Archive",
"(",
"sources",
"[",
"]",
"string",
",",
"destination",
"string",
")",
"error",
"{",
"err",
":=",
"tlz4",
".",
"CheckExt",
"(",
"destination",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fm... | // Archive creates a compressed tar file at destination
// containing the files listed in sources. The destination
// must end with ".tar.lz4" or ".tlz4". File paths can be
// those of regular files or directories; directories will
// be recursively added. | [
"Archive",
"creates",
"a",
"compressed",
"tar",
"file",
"at",
"destination",
"containing",
"the",
"files",
"listed",
"in",
"sources",
".",
"The",
"destination",
"must",
"end",
"with",
".",
"tar",
".",
"lz4",
"or",
".",
"tlz4",
".",
"File",
"paths",
"can",
... | 5e4ca701b6014549de7fa8734b3c7c5caf98af9e | https://github.com/mholt/archiver/blob/5e4ca701b6014549de7fa8734b3c7c5caf98af9e/tarlz4.go#L38-L45 | train |
mholt/archiver | tarlz4.go | Create | func (tlz4 *TarLz4) Create(out io.Writer) error {
tlz4.wrapWriter()
return tlz4.Tar.Create(out)
} | go | func (tlz4 *TarLz4) Create(out io.Writer) error {
tlz4.wrapWriter()
return tlz4.Tar.Create(out)
} | [
"func",
"(",
"tlz4",
"*",
"TarLz4",
")",
"Create",
"(",
"out",
"io",
".",
"Writer",
")",
"error",
"{",
"tlz4",
".",
"wrapWriter",
"(",
")",
"\n",
"return",
"tlz4",
".",
"Tar",
".",
"Create",
"(",
"out",
")",
"\n",
"}"
] | // Create opens tlz4 for writing a compressed
// tar archive to out. | [
"Create",
"opens",
"tlz4",
"for",
"writing",
"a",
"compressed",
"tar",
"archive",
"to",
"out",
"."
] | 5e4ca701b6014549de7fa8734b3c7c5caf98af9e | https://github.com/mholt/archiver/blob/5e4ca701b6014549de7fa8734b3c7c5caf98af9e/tarlz4.go#L63-L66 | train |
mholt/archiver | tarsz.go | Archive | func (tsz *TarSz) Archive(sources []string, destination string) error {
err := tsz.CheckExt(destination)
if err != nil {
return fmt.Errorf("output %s", err.Error())
}
tsz.wrapWriter()
return tsz.Tar.Archive(sources, destination)
} | go | func (tsz *TarSz) Archive(sources []string, destination string) error {
err := tsz.CheckExt(destination)
if err != nil {
return fmt.Errorf("output %s", err.Error())
}
tsz.wrapWriter()
return tsz.Tar.Archive(sources, destination)
} | [
"func",
"(",
"tsz",
"*",
"TarSz",
")",
"Archive",
"(",
"sources",
"[",
"]",
"string",
",",
"destination",
"string",
")",
"error",
"{",
"err",
":=",
"tsz",
".",
"CheckExt",
"(",
"destination",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",... | // Archive creates a compressed tar file at destination
// containing the files listed in sources. The destination
// must end with ".tar.sz" or ".tsz". File paths can be
// those of regular files or directories; directories will
// be recursively added. | [
"Archive",
"creates",
"a",
"compressed",
"tar",
"file",
"at",
"destination",
"containing",
"the",
"files",
"listed",
"in",
"sources",
".",
"The",
"destination",
"must",
"end",
"with",
".",
"tar",
".",
"sz",
"or",
".",
"tsz",
".",
"File",
"paths",
"can",
... | 5e4ca701b6014549de7fa8734b3c7c5caf98af9e | https://github.com/mholt/archiver/blob/5e4ca701b6014549de7fa8734b3c7c5caf98af9e/tarsz.go#L32-L39 | train |
mholt/archiver | tarsz.go | Create | func (tsz *TarSz) Create(out io.Writer) error {
tsz.wrapWriter()
return tsz.Tar.Create(out)
} | go | func (tsz *TarSz) Create(out io.Writer) error {
tsz.wrapWriter()
return tsz.Tar.Create(out)
} | [
"func",
"(",
"tsz",
"*",
"TarSz",
")",
"Create",
"(",
"out",
"io",
".",
"Writer",
")",
"error",
"{",
"tsz",
".",
"wrapWriter",
"(",
")",
"\n",
"return",
"tsz",
".",
"Tar",
".",
"Create",
"(",
"out",
")",
"\n",
"}"
] | // Create opens tsz for writing a compressed
// tar archive to out. | [
"Create",
"opens",
"tsz",
"for",
"writing",
"a",
"compressed",
"tar",
"archive",
"to",
"out",
"."
] | 5e4ca701b6014549de7fa8734b3c7c5caf98af9e | https://github.com/mholt/archiver/blob/5e4ca701b6014549de7fa8734b3c7c5caf98af9e/tarsz.go#L57-L60 | train |
mholt/archiver | targz.go | Archive | func (tgz *TarGz) Archive(sources []string, destination string) error {
err := tgz.CheckExt(destination)
if err != nil {
return fmt.Errorf("output %s", err.Error())
}
tgz.wrapWriter()
return tgz.Tar.Archive(sources, destination)
} | go | func (tgz *TarGz) Archive(sources []string, destination string) error {
err := tgz.CheckExt(destination)
if err != nil {
return fmt.Errorf("output %s", err.Error())
}
tgz.wrapWriter()
return tgz.Tar.Archive(sources, destination)
} | [
"func",
"(",
"tgz",
"*",
"TarGz",
")",
"Archive",
"(",
"sources",
"[",
"]",
"string",
",",
"destination",
"string",
")",
"error",
"{",
"err",
":=",
"tgz",
".",
"CheckExt",
"(",
"destination",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",... | // Archive creates a compressed tar file at destination
// containing the files listed in sources. The destination
// must end with ".tar.gz" or ".tgz". File paths can be
// those of regular files or directories; directories will
// be recursively added. | [
"Archive",
"creates",
"a",
"compressed",
"tar",
"file",
"at",
"destination",
"containing",
"the",
"files",
"listed",
"in",
"sources",
".",
"The",
"destination",
"must",
"end",
"with",
".",
"tar",
".",
"gz",
"or",
".",
"tgz",
".",
"File",
"paths",
"can",
... | 5e4ca701b6014549de7fa8734b3c7c5caf98af9e | https://github.com/mholt/archiver/blob/5e4ca701b6014549de7fa8734b3c7c5caf98af9e/targz.go#L34-L41 | train |
mholt/archiver | tarbz2.go | Archive | func (tbz2 *TarBz2) Archive(sources []string, destination string) error {
err := tbz2.CheckExt(destination)
if err != nil {
return fmt.Errorf("output %s", err.Error())
}
tbz2.wrapWriter()
return tbz2.Tar.Archive(sources, destination)
} | go | func (tbz2 *TarBz2) Archive(sources []string, destination string) error {
err := tbz2.CheckExt(destination)
if err != nil {
return fmt.Errorf("output %s", err.Error())
}
tbz2.wrapWriter()
return tbz2.Tar.Archive(sources, destination)
} | [
"func",
"(",
"tbz2",
"*",
"TarBz2",
")",
"Archive",
"(",
"sources",
"[",
"]",
"string",
",",
"destination",
"string",
")",
"error",
"{",
"err",
":=",
"tbz2",
".",
"CheckExt",
"(",
"destination",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fm... | // Archive creates a compressed tar file at destination
// containing the files listed in sources. The destination
// must end with ".tar.bz2" or ".tbz2". File paths can be
// those of regular files or directories; directories will
// be recursively added. | [
"Archive",
"creates",
"a",
"compressed",
"tar",
"file",
"at",
"destination",
"containing",
"the",
"files",
"listed",
"in",
"sources",
".",
"The",
"destination",
"must",
"end",
"with",
".",
"tar",
".",
"bz2",
"or",
".",
"tbz2",
".",
"File",
"paths",
"can",
... | 5e4ca701b6014549de7fa8734b3c7c5caf98af9e | https://github.com/mholt/archiver/blob/5e4ca701b6014549de7fa8734b3c7c5caf98af9e/tarbz2.go#L34-L41 | train |
mholt/archiver | tarbz2.go | Create | func (tbz2 *TarBz2) Create(out io.Writer) error {
tbz2.wrapWriter()
return tbz2.Tar.Create(out)
} | go | func (tbz2 *TarBz2) Create(out io.Writer) error {
tbz2.wrapWriter()
return tbz2.Tar.Create(out)
} | [
"func",
"(",
"tbz2",
"*",
"TarBz2",
")",
"Create",
"(",
"out",
"io",
".",
"Writer",
")",
"error",
"{",
"tbz2",
".",
"wrapWriter",
"(",
")",
"\n",
"return",
"tbz2",
".",
"Tar",
".",
"Create",
"(",
"out",
")",
"\n",
"}"
] | // Create opens tbz2 for writing a compressed
// tar archive to out. | [
"Create",
"opens",
"tbz2",
"for",
"writing",
"a",
"compressed",
"tar",
"archive",
"to",
"out",
"."
] | 5e4ca701b6014549de7fa8734b3c7c5caf98af9e | https://github.com/mholt/archiver/blob/5e4ca701b6014549de7fa8734b3c7c5caf98af9e/tarbz2.go#L59-L62 | train |
mholt/archiver | zip.go | Unarchive | func (z *Zip) Unarchive(source, destination string) error {
if !fileExists(destination) && z.MkdirAll {
err := mkdir(destination, 0755)
if err != nil {
return fmt.Errorf("preparing destination: %v", err)
}
}
file, err := os.Open(source)
if err != nil {
return fmt.Errorf("opening source file: %v", err)
... | go | func (z *Zip) Unarchive(source, destination string) error {
if !fileExists(destination) && z.MkdirAll {
err := mkdir(destination, 0755)
if err != nil {
return fmt.Errorf("preparing destination: %v", err)
}
}
file, err := os.Open(source)
if err != nil {
return fmt.Errorf("opening source file: %v", err)
... | [
"func",
"(",
"z",
"*",
"Zip",
")",
"Unarchive",
"(",
"source",
",",
"destination",
"string",
")",
"error",
"{",
"if",
"!",
"fileExists",
"(",
"destination",
")",
"&&",
"z",
".",
"MkdirAll",
"{",
"err",
":=",
"mkdir",
"(",
"destination",
",",
"0755",
... | // Unarchive unpacks the .zip file at source to destination.
// Destination will be treated as a folder name. | [
"Unarchive",
"unpacks",
"the",
".",
"zip",
"file",
"at",
"source",
"to",
"destination",
".",
"Destination",
"will",
"be",
"treated",
"as",
"a",
"folder",
"name",
"."
] | 5e4ca701b6014549de7fa8734b3c7c5caf98af9e | https://github.com/mholt/archiver/blob/5e4ca701b6014549de7fa8734b3c7c5caf98af9e/zip.go#L124-L177 | train |
mholt/archiver | zip.go | Create | func (z *Zip) Create(out io.Writer) error {
if z.zw != nil {
return fmt.Errorf("zip archive is already created for writing")
}
z.zw = zip.NewWriter(out)
if z.CompressionLevel != flate.DefaultCompression {
z.zw.RegisterCompressor(zip.Deflate, func(out io.Writer) (io.WriteCloser, error) {
return flate.NewWrite... | go | func (z *Zip) Create(out io.Writer) error {
if z.zw != nil {
return fmt.Errorf("zip archive is already created for writing")
}
z.zw = zip.NewWriter(out)
if z.CompressionLevel != flate.DefaultCompression {
z.zw.RegisterCompressor(zip.Deflate, func(out io.Writer) (io.WriteCloser, error) {
return flate.NewWrite... | [
"func",
"(",
"z",
"*",
"Zip",
")",
"Create",
"(",
"out",
"io",
".",
"Writer",
")",
"error",
"{",
"if",
"z",
".",
"zw",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"z",
".",
"zw",
"=",
"zip",
".",... | // Create opens z for writing a ZIP archive to out. | [
"Create",
"opens",
"z",
"for",
"writing",
"a",
"ZIP",
"archive",
"to",
"out",
"."
] | 5e4ca701b6014549de7fa8734b3c7c5caf98af9e | https://github.com/mholt/archiver/blob/5e4ca701b6014549de7fa8734b3c7c5caf98af9e/zip.go#L285-L296 | train |
mholt/archiver | zip.go | Write | func (z *Zip) Write(f File) error {
if z.zw == nil {
return fmt.Errorf("zip archive was not created for writing first")
}
if f.FileInfo == nil {
return fmt.Errorf("no file info")
}
if f.FileInfo.Name() == "" {
return fmt.Errorf("missing file name")
}
header, err := zip.FileInfoHeader(f)
if err != nil {
... | go | func (z *Zip) Write(f File) error {
if z.zw == nil {
return fmt.Errorf("zip archive was not created for writing first")
}
if f.FileInfo == nil {
return fmt.Errorf("no file info")
}
if f.FileInfo.Name() == "" {
return fmt.Errorf("missing file name")
}
header, err := zip.FileInfoHeader(f)
if err != nil {
... | [
"func",
"(",
"z",
"*",
"Zip",
")",
"Write",
"(",
"f",
"File",
")",
"error",
"{",
"if",
"z",
".",
"zw",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"f",
".",
"FileInfo",
"==",
"nil",
"{",
"r... | // Write writes f to z, which must have been opened for writing first. | [
"Write",
"writes",
"f",
"to",
"z",
"which",
"must",
"have",
"been",
"opened",
"for",
"writing",
"first",
"."
] | 5e4ca701b6014549de7fa8734b3c7c5caf98af9e | https://github.com/mholt/archiver/blob/5e4ca701b6014549de7fa8734b3c7c5caf98af9e/zip.go#L299-L333 | train |
mholt/archiver | zip.go | Open | func (z *Zip) Open(in io.Reader, size int64) error {
inRdrAt, ok := in.(io.ReaderAt)
if !ok {
return fmt.Errorf("reader must be io.ReaderAt")
}
if z.zr != nil {
return fmt.Errorf("zip archive is already open for reading")
}
var err error
z.zr, err = zip.NewReader(inRdrAt, size)
if err != nil {
return fmt.... | go | func (z *Zip) Open(in io.Reader, size int64) error {
inRdrAt, ok := in.(io.ReaderAt)
if !ok {
return fmt.Errorf("reader must be io.ReaderAt")
}
if z.zr != nil {
return fmt.Errorf("zip archive is already open for reading")
}
var err error
z.zr, err = zip.NewReader(inRdrAt, size)
if err != nil {
return fmt.... | [
"func",
"(",
"z",
"*",
"Zip",
")",
"Open",
"(",
"in",
"io",
".",
"Reader",
",",
"size",
"int64",
")",
"error",
"{",
"inRdrAt",
",",
"ok",
":=",
"in",
".",
"(",
"io",
".",
"ReaderAt",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"fmt",
".",
"Err... | // Open opens z for reading an archive from in,
// which is expected to have the given size and
// which must be an io.ReaderAt. | [
"Open",
"opens",
"z",
"for",
"reading",
"an",
"archive",
"from",
"in",
"which",
"is",
"expected",
"to",
"have",
"the",
"given",
"size",
"and",
"which",
"must",
"be",
"an",
"io",
".",
"ReaderAt",
"."
] | 5e4ca701b6014549de7fa8734b3c7c5caf98af9e | https://github.com/mholt/archiver/blob/5e4ca701b6014549de7fa8734b3c7c5caf98af9e/zip.go#L366-L381 | train |
mholt/archiver | zip.go | Read | func (z *Zip) Read() (File, error) {
if z.zr == nil {
return File{}, fmt.Errorf("zip archive is not open")
}
if z.ridx >= len(z.zr.File) {
return File{}, io.EOF
}
// access the file and increment counter so that
// if there is an error processing this file, the
// caller can still iterate to the next file
... | go | func (z *Zip) Read() (File, error) {
if z.zr == nil {
return File{}, fmt.Errorf("zip archive is not open")
}
if z.ridx >= len(z.zr.File) {
return File{}, io.EOF
}
// access the file and increment counter so that
// if there is an error processing this file, the
// caller can still iterate to the next file
... | [
"func",
"(",
"z",
"*",
"Zip",
")",
"Read",
"(",
")",
"(",
"File",
",",
"error",
")",
"{",
"if",
"z",
".",
"zr",
"==",
"nil",
"{",
"return",
"File",
"{",
"}",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"z",
"."... | // Read reads the next file from z, which must have
// already been opened for reading. If there are no
// more files, the error is io.EOF. The File must
// be closed when finished reading from it. | [
"Read",
"reads",
"the",
"next",
"file",
"from",
"z",
"which",
"must",
"have",
"already",
"been",
"opened",
"for",
"reading",
".",
"If",
"there",
"are",
"no",
"more",
"files",
"the",
"error",
"is",
"io",
".",
"EOF",
".",
"The",
"File",
"must",
"be",
"... | 5e4ca701b6014549de7fa8734b3c7c5caf98af9e | https://github.com/mholt/archiver/blob/5e4ca701b6014549de7fa8734b3c7c5caf98af9e/zip.go#L387-L413 | train |
mholt/archiver | zip.go | Extract | func (z *Zip) Extract(source, target, destination string) error {
// target refers to a path inside the archive, which should be clean also
target = path.Clean(target)
// if the target ends up being a directory, then
// we will continue walking and extracting files
// until we are no longer within that directory
... | go | func (z *Zip) Extract(source, target, destination string) error {
// target refers to a path inside the archive, which should be clean also
target = path.Clean(target)
// if the target ends up being a directory, then
// we will continue walking and extracting files
// until we are no longer within that directory
... | [
"func",
"(",
"z",
"*",
"Zip",
")",
"Extract",
"(",
"source",
",",
"target",
",",
"destination",
"string",
")",
"error",
"{",
"// target refers to a path inside the archive, which should be clean also",
"target",
"=",
"path",
".",
"Clean",
"(",
"target",
")",
"\n\n... | // Extract extracts a single file from the zip archive.
// If the target is a directory, the entire folder will
// be extracted into destination. | [
"Extract",
"extracts",
"a",
"single",
"file",
"from",
"the",
"zip",
"archive",
".",
"If",
"the",
"target",
"is",
"a",
"directory",
"the",
"entire",
"folder",
"will",
"be",
"extracted",
"into",
"destination",
"."
] | 5e4ca701b6014549de7fa8734b3c7c5caf98af9e | https://github.com/mholt/archiver/blob/5e4ca701b6014549de7fa8734b3c7c5caf98af9e/zip.go#L471-L520 | train |
mholt/archiver | zip.go | NewZip | func NewZip() *Zip {
return &Zip{
CompressionLevel: flate.DefaultCompression,
MkdirAll: true,
SelectiveCompression: true,
}
} | go | func NewZip() *Zip {
return &Zip{
CompressionLevel: flate.DefaultCompression,
MkdirAll: true,
SelectiveCompression: true,
}
} | [
"func",
"NewZip",
"(",
")",
"*",
"Zip",
"{",
"return",
"&",
"Zip",
"{",
"CompressionLevel",
":",
"flate",
".",
"DefaultCompression",
",",
"MkdirAll",
":",
"true",
",",
"SelectiveCompression",
":",
"true",
",",
"}",
"\n",
"}"
] | // NewZip returns a new, default instance ready to be customized and used. | [
"NewZip",
"returns",
"a",
"new",
"default",
"instance",
"ready",
"to",
"be",
"customized",
"and",
"used",
"."
] | 5e4ca701b6014549de7fa8734b3c7c5caf98af9e | https://github.com/mholt/archiver/blob/5e4ca701b6014549de7fa8734b3c7c5caf98af9e/zip.go#L545-L551 | train |
mholt/archiver | archiver.go | Archive | func Archive(sources []string, destination string) error {
aIface, err := ByExtension(destination)
if err != nil {
return err
}
a, ok := aIface.(Archiver)
if !ok {
return fmt.Errorf("format specified by destination filename is not an archive format: %s (%T)", destination, aIface)
}
return a.Archive(sources, ... | go | func Archive(sources []string, destination string) error {
aIface, err := ByExtension(destination)
if err != nil {
return err
}
a, ok := aIface.(Archiver)
if !ok {
return fmt.Errorf("format specified by destination filename is not an archive format: %s (%T)", destination, aIface)
}
return a.Archive(sources, ... | [
"func",
"Archive",
"(",
"sources",
"[",
"]",
"string",
",",
"destination",
"string",
")",
"error",
"{",
"aIface",
",",
"err",
":=",
"ByExtension",
"(",
"destination",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"a",
",... | // Archive creates an archive of the source files to a new file at destination.
// The archive format is chosen implicitly by file extension. | [
"Archive",
"creates",
"an",
"archive",
"of",
"the",
"source",
"files",
"to",
"a",
"new",
"file",
"at",
"destination",
".",
"The",
"archive",
"format",
"is",
"chosen",
"implicitly",
"by",
"file",
"extension",
"."
] | 5e4ca701b6014549de7fa8734b3c7c5caf98af9e | https://github.com/mholt/archiver/blob/5e4ca701b6014549de7fa8734b3c7c5caf98af9e/archiver.go#L186-L196 | train |
mholt/archiver | archiver.go | Unarchive | func Unarchive(source, destination string) error {
uaIface, err := ByExtension(source)
if err != nil {
return err
}
u, ok := uaIface.(Unarchiver)
if !ok {
return fmt.Errorf("format specified by source filename is not an archive format: %s (%T)", source, uaIface)
}
return u.Unarchive(source, destination)
} | go | func Unarchive(source, destination string) error {
uaIface, err := ByExtension(source)
if err != nil {
return err
}
u, ok := uaIface.(Unarchiver)
if !ok {
return fmt.Errorf("format specified by source filename is not an archive format: %s (%T)", source, uaIface)
}
return u.Unarchive(source, destination)
} | [
"func",
"Unarchive",
"(",
"source",
",",
"destination",
"string",
")",
"error",
"{",
"uaIface",
",",
"err",
":=",
"ByExtension",
"(",
"source",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"u",
",",
"ok",
":=",
"uaIface... | // Unarchive unarchives the given archive file into the destination folder.
// The archive format is selected implicitly. | [
"Unarchive",
"unarchives",
"the",
"given",
"archive",
"file",
"into",
"the",
"destination",
"folder",
".",
"The",
"archive",
"format",
"is",
"selected",
"implicitly",
"."
] | 5e4ca701b6014549de7fa8734b3c7c5caf98af9e | https://github.com/mholt/archiver/blob/5e4ca701b6014549de7fa8734b3c7c5caf98af9e/archiver.go#L200-L210 | train |
mholt/archiver | archiver.go | Walk | func Walk(archive string, walkFn WalkFunc) error {
wIface, err := ByExtension(archive)
if err != nil {
return err
}
w, ok := wIface.(Walker)
if !ok {
return fmt.Errorf("format specified by archive filename is not a walker format: %s (%T)", archive, wIface)
}
return w.Walk(archive, walkFn)
} | go | func Walk(archive string, walkFn WalkFunc) error {
wIface, err := ByExtension(archive)
if err != nil {
return err
}
w, ok := wIface.(Walker)
if !ok {
return fmt.Errorf("format specified by archive filename is not a walker format: %s (%T)", archive, wIface)
}
return w.Walk(archive, walkFn)
} | [
"func",
"Walk",
"(",
"archive",
"string",
",",
"walkFn",
"WalkFunc",
")",
"error",
"{",
"wIface",
",",
"err",
":=",
"ByExtension",
"(",
"archive",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"w",
",",
"ok",
":=",
"wI... | // Walk calls walkFn for each file within the given archive file.
// The archive format is chosen implicitly. | [
"Walk",
"calls",
"walkFn",
"for",
"each",
"file",
"within",
"the",
"given",
"archive",
"file",
".",
"The",
"archive",
"format",
"is",
"chosen",
"implicitly",
"."
] | 5e4ca701b6014549de7fa8734b3c7c5caf98af9e | https://github.com/mholt/archiver/blob/5e4ca701b6014549de7fa8734b3c7c5caf98af9e/archiver.go#L214-L224 | train |
mholt/archiver | archiver.go | Extract | func Extract(source, target, destination string) error {
eIface, err := ByExtension(source)
if err != nil {
return err
}
e, ok := eIface.(Extractor)
if !ok {
return fmt.Errorf("format specified by source filename is not an extractor format: %s (%T)", source, eIface)
}
return e.Extract(source, target, destina... | go | func Extract(source, target, destination string) error {
eIface, err := ByExtension(source)
if err != nil {
return err
}
e, ok := eIface.(Extractor)
if !ok {
return fmt.Errorf("format specified by source filename is not an extractor format: %s (%T)", source, eIface)
}
return e.Extract(source, target, destina... | [
"func",
"Extract",
"(",
"source",
",",
"target",
",",
"destination",
"string",
")",
"error",
"{",
"eIface",
",",
"err",
":=",
"ByExtension",
"(",
"source",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"e",
",",
"ok",
... | // Extract extracts a single file from the given source archive. If the target
// is a directory, the entire folder will be extracted into destination. The
// archive format is chosen implicitly. | [
"Extract",
"extracts",
"a",
"single",
"file",
"from",
"the",
"given",
"source",
"archive",
".",
"If",
"the",
"target",
"is",
"a",
"directory",
"the",
"entire",
"folder",
"will",
"be",
"extracted",
"into",
"destination",
".",
"The",
"archive",
"format",
"is",... | 5e4ca701b6014549de7fa8734b3c7c5caf98af9e | https://github.com/mholt/archiver/blob/5e4ca701b6014549de7fa8734b3c7c5caf98af9e/archiver.go#L229-L239 | train |
mholt/archiver | archiver.go | CompressFile | func CompressFile(source, destination string) error {
cIface, err := ByExtension(destination)
if err != nil {
return err
}
c, ok := cIface.(Compressor)
if !ok {
return fmt.Errorf("format specified by destination filename is not a recognized compression algorithm: %s", destination)
}
return FileCompressor{Com... | go | func CompressFile(source, destination string) error {
cIface, err := ByExtension(destination)
if err != nil {
return err
}
c, ok := cIface.(Compressor)
if !ok {
return fmt.Errorf("format specified by destination filename is not a recognized compression algorithm: %s", destination)
}
return FileCompressor{Com... | [
"func",
"CompressFile",
"(",
"source",
",",
"destination",
"string",
")",
"error",
"{",
"cIface",
",",
"err",
":=",
"ByExtension",
"(",
"destination",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"c",
",",
"ok",
":=",
"... | // CompressFile is a convenience function to simply compress a file.
// The compression algorithm is selected implicitly based on the
// destination's extension. | [
"CompressFile",
"is",
"a",
"convenience",
"function",
"to",
"simply",
"compress",
"a",
"file",
".",
"The",
"compression",
"algorithm",
"is",
"selected",
"implicitly",
"based",
"on",
"the",
"destination",
"s",
"extension",
"."
] | 5e4ca701b6014549de7fa8734b3c7c5caf98af9e | https://github.com/mholt/archiver/blob/5e4ca701b6014549de7fa8734b3c7c5caf98af9e/archiver.go#L244-L254 | train |
mholt/archiver | archiver.go | DecompressFile | func DecompressFile(source, destination string) error {
cIface, err := ByExtension(source)
if err != nil {
return err
}
c, ok := cIface.(Decompressor)
if !ok {
return fmt.Errorf("format specified by source filename is not a recognized compression algorithm: %s", source)
}
return FileCompressor{Decompressor: ... | go | func DecompressFile(source, destination string) error {
cIface, err := ByExtension(source)
if err != nil {
return err
}
c, ok := cIface.(Decompressor)
if !ok {
return fmt.Errorf("format specified by source filename is not a recognized compression algorithm: %s", source)
}
return FileCompressor{Decompressor: ... | [
"func",
"DecompressFile",
"(",
"source",
",",
"destination",
"string",
")",
"error",
"{",
"cIface",
",",
"err",
":=",
"ByExtension",
"(",
"source",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"c",
",",
"ok",
":=",
"cIf... | // DecompressFile is a convenience function to simply compress a file.
// The compression algorithm is selected implicitly based on the
// source's extension. | [
"DecompressFile",
"is",
"a",
"convenience",
"function",
"to",
"simply",
"compress",
"a",
"file",
".",
"The",
"compression",
"algorithm",
"is",
"selected",
"implicitly",
"based",
"on",
"the",
"source",
"s",
"extension",
"."
] | 5e4ca701b6014549de7fa8734b3c7c5caf98af9e | https://github.com/mholt/archiver/blob/5e4ca701b6014549de7fa8734b3c7c5caf98af9e/archiver.go#L259-L269 | train |
mholt/archiver | archiver.go | within | func within(parent, sub string) bool {
rel, err := filepath.Rel(parent, sub)
if err != nil {
return false
}
return !strings.Contains(rel, "..")
} | go | func within(parent, sub string) bool {
rel, err := filepath.Rel(parent, sub)
if err != nil {
return false
}
return !strings.Contains(rel, "..")
} | [
"func",
"within",
"(",
"parent",
",",
"sub",
"string",
")",
"bool",
"{",
"rel",
",",
"err",
":=",
"filepath",
".",
"Rel",
"(",
"parent",
",",
"sub",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"!",
"str... | // within returns true if sub is within or equal to parent. | [
"within",
"returns",
"true",
"if",
"sub",
"is",
"within",
"or",
"equal",
"to",
"parent",
"."
] | 5e4ca701b6014549de7fa8734b3c7c5caf98af9e | https://github.com/mholt/archiver/blob/5e4ca701b6014549de7fa8734b3c7c5caf98af9e/archiver.go#L355-L361 | train |
mholt/archiver | archiver.go | multipleTopLevels | func multipleTopLevels(paths []string) bool {
if len(paths) < 2 {
return false
}
var lastTop string
for _, p := range paths {
p = strings.TrimPrefix(strings.Replace(p, `\`, "/", -1), "/")
for {
next := path.Dir(p)
if next == "." {
break
}
p = next
}
if lastTop == "" {
lastTop = p
}
... | go | func multipleTopLevels(paths []string) bool {
if len(paths) < 2 {
return false
}
var lastTop string
for _, p := range paths {
p = strings.TrimPrefix(strings.Replace(p, `\`, "/", -1), "/")
for {
next := path.Dir(p)
if next == "." {
break
}
p = next
}
if lastTop == "" {
lastTop = p
}
... | [
"func",
"multipleTopLevels",
"(",
"paths",
"[",
"]",
"string",
")",
"bool",
"{",
"if",
"len",
"(",
"paths",
")",
"<",
"2",
"{",
"return",
"false",
"\n",
"}",
"\n",
"var",
"lastTop",
"string",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"paths",
"{",... | // multipleTopLevels returns true if the paths do not
// share a common top-level folder. | [
"multipleTopLevels",
"returns",
"true",
"if",
"the",
"paths",
"do",
"not",
"share",
"a",
"common",
"top",
"-",
"level",
"folder",
"."
] | 5e4ca701b6014549de7fa8734b3c7c5caf98af9e | https://github.com/mholt/archiver/blob/5e4ca701b6014549de7fa8734b3c7c5caf98af9e/archiver.go#L365-L387 | train |
mholt/archiver | archiver.go | folderNameFromFileName | func folderNameFromFileName(filename string) string {
base := filepath.Base(filename)
firstDot := strings.Index(base, ".")
if firstDot > -1 {
return base[:firstDot]
}
return base
} | go | func folderNameFromFileName(filename string) string {
base := filepath.Base(filename)
firstDot := strings.Index(base, ".")
if firstDot > -1 {
return base[:firstDot]
}
return base
} | [
"func",
"folderNameFromFileName",
"(",
"filename",
"string",
")",
"string",
"{",
"base",
":=",
"filepath",
".",
"Base",
"(",
"filename",
")",
"\n",
"firstDot",
":=",
"strings",
".",
"Index",
"(",
"base",
",",
"\"",
"\"",
")",
"\n",
"if",
"firstDot",
">",... | // folderNameFromFileName returns a name for a folder
// that is suitable based on the filename, which will
// be stripped of its extensions. | [
"folderNameFromFileName",
"returns",
"a",
"name",
"for",
"a",
"folder",
"that",
"is",
"suitable",
"based",
"on",
"the",
"filename",
"which",
"will",
"be",
"stripped",
"of",
"its",
"extensions",
"."
] | 5e4ca701b6014549de7fa8734b3c7c5caf98af9e | https://github.com/mholt/archiver/blob/5e4ca701b6014549de7fa8734b3c7c5caf98af9e/archiver.go#L392-L399 | train |
mholt/archiver | archiver.go | makeNameInArchive | func makeNameInArchive(sourceInfo os.FileInfo, source, baseDir, fpath string) (string, error) {
name := filepath.Base(fpath) // start with the file or dir name
if sourceInfo.IsDir() {
// preserve internal directory structure; that's the path components
// between the source directory's leaf and this file's leaf
... | go | func makeNameInArchive(sourceInfo os.FileInfo, source, baseDir, fpath string) (string, error) {
name := filepath.Base(fpath) // start with the file or dir name
if sourceInfo.IsDir() {
// preserve internal directory structure; that's the path components
// between the source directory's leaf and this file's leaf
... | [
"func",
"makeNameInArchive",
"(",
"sourceInfo",
"os",
".",
"FileInfo",
",",
"source",
",",
"baseDir",
",",
"fpath",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"name",
":=",
"filepath",
".",
"Base",
"(",
"fpath",
")",
"// start with the file or dir... | // makeNameInArchive returns the filename for the file given by fpath to be used within
// the archive. sourceInfo is the FileInfo obtained by calling os.Stat on source, and baseDir
// is an optional base directory that becomes the root of the archive. fpath should be the
// unaltered file path of the file given to a f... | [
"makeNameInArchive",
"returns",
"the",
"filename",
"for",
"the",
"file",
"given",
"by",
"fpath",
"to",
"be",
"used",
"within",
"the",
"archive",
".",
"sourceInfo",
"is",
"the",
"FileInfo",
"obtained",
"by",
"calling",
"os",
".",
"Stat",
"on",
"source",
"and"... | 5e4ca701b6014549de7fa8734b3c7c5caf98af9e | https://github.com/mholt/archiver/blob/5e4ca701b6014549de7fa8734b3c7c5caf98af9e/archiver.go#L405-L419 | train |
mholt/archiver | archiver.go | NameInArchive | func NameInArchive(sourceInfo os.FileInfo, source, fpath string) (string, error) {
return makeNameInArchive(sourceInfo, source, "", fpath)
} | go | func NameInArchive(sourceInfo os.FileInfo, source, fpath string) (string, error) {
return makeNameInArchive(sourceInfo, source, "", fpath)
} | [
"func",
"NameInArchive",
"(",
"sourceInfo",
"os",
".",
"FileInfo",
",",
"source",
",",
"fpath",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"return",
"makeNameInArchive",
"(",
"sourceInfo",
",",
"source",
",",
"\"",
"\"",
",",
"fpath",
")",
"\n... | // NameInArchive returns a name for the file at fpath suitable for
// the inside of an archive. The source and its associated sourceInfo
// is the path where walking a directory started, and if no directory
// was walked, source may == fpath. The returned name is essentially
// the components of the path between source... | [
"NameInArchive",
"returns",
"a",
"name",
"for",
"the",
"file",
"at",
"fpath",
"suitable",
"for",
"the",
"inside",
"of",
"an",
"archive",
".",
"The",
"source",
"and",
"its",
"associated",
"sourceInfo",
"is",
"the",
"path",
"where",
"walking",
"a",
"directory"... | 5e4ca701b6014549de7fa8734b3c7c5caf98af9e | https://github.com/mholt/archiver/blob/5e4ca701b6014549de7fa8734b3c7c5caf98af9e/archiver.go#L427-L429 | train |
mholt/archiver | archiver.go | ByExtension | func ByExtension(filename string) (interface{}, error) {
var ec interface{}
for _, c := range extCheckers {
if err := c.CheckExt(filename); err == nil {
ec = c
break
}
}
switch ec.(type) {
case *Rar:
return NewRar(), nil
case *Tar:
return NewTar(), nil
case *TarBz2:
return NewTarBz2(), nil
case ... | go | func ByExtension(filename string) (interface{}, error) {
var ec interface{}
for _, c := range extCheckers {
if err := c.CheckExt(filename); err == nil {
ec = c
break
}
}
switch ec.(type) {
case *Rar:
return NewRar(), nil
case *Tar:
return NewTar(), nil
case *TarBz2:
return NewTarBz2(), nil
case ... | [
"func",
"ByExtension",
"(",
"filename",
"string",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"var",
"ec",
"interface",
"{",
"}",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"extCheckers",
"{",
"if",
"err",
":=",
"c",
".",
"CheckExt",
"... | // ByExtension returns an archiver and unarchiver, or compressor
// and decompressor, based on the extension of the filename. | [
"ByExtension",
"returns",
"an",
"archiver",
"and",
"unarchiver",
"or",
"compressor",
"and",
"decompressor",
"based",
"on",
"the",
"extension",
"of",
"the",
"filename",
"."
] | 5e4ca701b6014549de7fa8734b3c7c5caf98af9e | https://github.com/mholt/archiver/blob/5e4ca701b6014549de7fa8734b3c7c5caf98af9e/archiver.go#L433-L470 | train |
mholt/archiver | archiver.go | ByHeader | func ByHeader(input io.ReadSeeker) (Unarchiver, error) {
var matcher Matcher
for _, m := range matchers {
ok, err := m.Match(input)
if err != nil {
return nil, fmt.Errorf("matching on format %s: %v", m, err)
}
if ok {
matcher = m
break
}
}
switch matcher.(type) {
case *Zip:
return NewZip(), ni... | go | func ByHeader(input io.ReadSeeker) (Unarchiver, error) {
var matcher Matcher
for _, m := range matchers {
ok, err := m.Match(input)
if err != nil {
return nil, fmt.Errorf("matching on format %s: %v", m, err)
}
if ok {
matcher = m
break
}
}
switch matcher.(type) {
case *Zip:
return NewZip(), ni... | [
"func",
"ByHeader",
"(",
"input",
"io",
".",
"ReadSeeker",
")",
"(",
"Unarchiver",
",",
"error",
")",
"{",
"var",
"matcher",
"Matcher",
"\n",
"for",
"_",
",",
"m",
":=",
"range",
"matchers",
"{",
"ok",
",",
"err",
":=",
"m",
".",
"Match",
"(",
"inp... | // ByHeader returns the unarchiver value that matches the input's
// file header. It does not affect the current read position.
// If the file's header is not a recognized archive format, then
// ErrFormatNotRecognized will be returned. | [
"ByHeader",
"returns",
"the",
"unarchiver",
"value",
"that",
"matches",
"the",
"input",
"s",
"file",
"header",
".",
"It",
"does",
"not",
"affect",
"the",
"current",
"read",
"position",
".",
"If",
"the",
"file",
"s",
"header",
"is",
"not",
"a",
"recognized"... | 5e4ca701b6014549de7fa8734b3c7c5caf98af9e | https://github.com/mholt/archiver/blob/5e4ca701b6014549de7fa8734b3c7c5caf98af9e/archiver.go#L476-L497 | train |
mholt/archiver | filecompressor.go | CompressFile | func (fc FileCompressor) CompressFile(source, destination string) error {
if err := fc.CheckExt(destination); err != nil {
return err
}
if fc.Compressor == nil {
return fmt.Errorf("no compressor specified")
}
if !fc.OverwriteExisting && fileExists(destination) {
return fmt.Errorf("file exists: %s", destinati... | go | func (fc FileCompressor) CompressFile(source, destination string) error {
if err := fc.CheckExt(destination); err != nil {
return err
}
if fc.Compressor == nil {
return fmt.Errorf("no compressor specified")
}
if !fc.OverwriteExisting && fileExists(destination) {
return fmt.Errorf("file exists: %s", destinati... | [
"func",
"(",
"fc",
"FileCompressor",
")",
"CompressFile",
"(",
"source",
",",
"destination",
"string",
")",
"error",
"{",
"if",
"err",
":=",
"fc",
".",
"CheckExt",
"(",
"destination",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",... | // CompressFile reads the source file and compresses it to destination.
// The destination must have a matching extension. | [
"CompressFile",
"reads",
"the",
"source",
"file",
"and",
"compresses",
"it",
"to",
"destination",
".",
"The",
"destination",
"must",
"have",
"a",
"matching",
"extension",
"."
] | 5e4ca701b6014549de7fa8734b3c7c5caf98af9e | https://github.com/mholt/archiver/blob/5e4ca701b6014549de7fa8734b3c7c5caf98af9e/filecompressor.go#L19-L43 | train |
mholt/archiver | filecompressor.go | DecompressFile | func (fc FileCompressor) DecompressFile(source, destination string) error {
if fc.Decompressor == nil {
return fmt.Errorf("no decompressor specified")
}
if !fc.OverwriteExisting && fileExists(destination) {
return fmt.Errorf("file exists: %s", destination)
}
in, err := os.Open(source)
if err != nil {
retur... | go | func (fc FileCompressor) DecompressFile(source, destination string) error {
if fc.Decompressor == nil {
return fmt.Errorf("no decompressor specified")
}
if !fc.OverwriteExisting && fileExists(destination) {
return fmt.Errorf("file exists: %s", destination)
}
in, err := os.Open(source)
if err != nil {
retur... | [
"func",
"(",
"fc",
"FileCompressor",
")",
"DecompressFile",
"(",
"source",
",",
"destination",
"string",
")",
"error",
"{",
"if",
"fc",
".",
"Decompressor",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
... | // DecompressFile reads the source file and decompresses it to destination. | [
"DecompressFile",
"reads",
"the",
"source",
"file",
"and",
"decompresses",
"it",
"to",
"destination",
"."
] | 5e4ca701b6014549de7fa8734b3c7c5caf98af9e | https://github.com/mholt/archiver/blob/5e4ca701b6014549de7fa8734b3c7c5caf98af9e/filecompressor.go#L46-L67 | train |
GeertJohan/go.rice | config.go | FindBox | func (c *Config) FindBox(boxName string) (*Box, error) {
return findBox(boxName, c.LocateOrder)
} | go | func (c *Config) FindBox(boxName string) (*Box, error) {
return findBox(boxName, c.LocateOrder)
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"FindBox",
"(",
"boxName",
"string",
")",
"(",
"*",
"Box",
",",
"error",
")",
"{",
"return",
"findBox",
"(",
"boxName",
",",
"c",
".",
"LocateOrder",
")",
"\n",
"}"
] | // FindBox searches for boxes using the LocateOrder of the config. | [
"FindBox",
"searches",
"for",
"boxes",
"using",
"the",
"LocateOrder",
"of",
"the",
"config",
"."
] | c880e3cd4dd81db36b423e83dc0aeea4dca93774 | https://github.com/GeertJohan/go.rice/blob/c880e3cd4dd81db36b423e83dc0aeea4dca93774/config.go#L26-L28 | train |
GeertJohan/go.rice | config.go | MustFindBox | func (c *Config) MustFindBox(boxName string) *Box {
box, err := findBox(boxName, c.LocateOrder)
if err != nil {
panic(err)
}
return box
} | go | func (c *Config) MustFindBox(boxName string) *Box {
box, err := findBox(boxName, c.LocateOrder)
if err != nil {
panic(err)
}
return box
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"MustFindBox",
"(",
"boxName",
"string",
")",
"*",
"Box",
"{",
"box",
",",
"err",
":=",
"findBox",
"(",
"boxName",
",",
"c",
".",
"LocateOrder",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
... | // MustFindBox searches for boxes using the LocateOrder of the config, like
// FindBox does. It does not return an error, instead it panics when an error
// occurs. | [
"MustFindBox",
"searches",
"for",
"boxes",
"using",
"the",
"LocateOrder",
"of",
"the",
"config",
"like",
"FindBox",
"does",
".",
"It",
"does",
"not",
"return",
"an",
"error",
"instead",
"it",
"panics",
"when",
"an",
"error",
"occurs",
"."
] | c880e3cd4dd81db36b423e83dc0aeea4dca93774 | https://github.com/GeertJohan/go.rice/blob/c880e3cd4dd81db36b423e83dc0aeea4dca93774/config.go#L33-L39 | train |
GeertJohan/go.rice | embedded/embedded.go | Link | func (e *EmbeddedBox) Link() {
for _, ed := range e.Dirs {
ed.ChildDirs = make([]*EmbeddedDir, 0)
ed.ChildFiles = make([]*EmbeddedFile, 0)
}
for path, ed := range e.Dirs {
// skip for root, it'll create a recursion
if path == "" {
continue
}
parentDirpath, _ := filepath.Split(path)
if strings.HasSuf... | go | func (e *EmbeddedBox) Link() {
for _, ed := range e.Dirs {
ed.ChildDirs = make([]*EmbeddedDir, 0)
ed.ChildFiles = make([]*EmbeddedFile, 0)
}
for path, ed := range e.Dirs {
// skip for root, it'll create a recursion
if path == "" {
continue
}
parentDirpath, _ := filepath.Split(path)
if strings.HasSuf... | [
"func",
"(",
"e",
"*",
"EmbeddedBox",
")",
"Link",
"(",
")",
"{",
"for",
"_",
",",
"ed",
":=",
"range",
"e",
".",
"Dirs",
"{",
"ed",
".",
"ChildDirs",
"=",
"make",
"(",
"[",
"]",
"*",
"EmbeddedDir",
",",
"0",
")",
"\n",
"ed",
".",
"ChildFiles",... | // Link creates the ChildDirs and ChildFiles links in all EmbeddedDir's | [
"Link",
"creates",
"the",
"ChildDirs",
"and",
"ChildFiles",
"links",
"in",
"all",
"EmbeddedDir",
"s"
] | c880e3cd4dd81db36b423e83dc0aeea4dca93774 | https://github.com/GeertJohan/go.rice/blob/c880e3cd4dd81db36b423e83dc0aeea4dca93774/embedded/embedded.go#L26-L57 | train |
GeertJohan/go.rice | embedded/embedded.go | RegisterEmbeddedBox | func RegisterEmbeddedBox(name string, box *EmbeddedBox) {
if _, exists := EmbeddedBoxes[name]; exists {
panic(fmt.Sprintf("EmbeddedBox with name `%s` exists already", name))
}
EmbeddedBoxes[name] = box
} | go | func RegisterEmbeddedBox(name string, box *EmbeddedBox) {
if _, exists := EmbeddedBoxes[name]; exists {
panic(fmt.Sprintf("EmbeddedBox with name `%s` exists already", name))
}
EmbeddedBoxes[name] = box
} | [
"func",
"RegisterEmbeddedBox",
"(",
"name",
"string",
",",
"box",
"*",
"EmbeddedBox",
")",
"{",
"if",
"_",
",",
"exists",
":=",
"EmbeddedBoxes",
"[",
"name",
"]",
";",
"exists",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"name",
... | // RegisterEmbeddedBox registers an EmbeddedBox | [
"RegisterEmbeddedBox",
"registers",
"an",
"EmbeddedBox"
] | c880e3cd4dd81db36b423e83dc0aeea4dca93774 | https://github.com/GeertJohan/go.rice/blob/c880e3cd4dd81db36b423e83dc0aeea4dca93774/embedded/embedded.go#L78-L83 | train |
GeertJohan/go.rice | box.go | MustFindBox | func MustFindBox(name string) *Box {
box, err := findBox(name, defaultLocateOrder)
if err != nil {
panic(err)
}
return box
} | go | func MustFindBox(name string) *Box {
box, err := findBox(name, defaultLocateOrder)
if err != nil {
panic(err)
}
return box
} | [
"func",
"MustFindBox",
"(",
"name",
"string",
")",
"*",
"Box",
"{",
"box",
",",
"err",
":=",
"findBox",
"(",
"name",
",",
"defaultLocateOrder",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"box",
"\... | // MustFindBox returns a Box instance for given name, like FindBox does.
// It does not return an error, instead it panics when an error occurs. | [
"MustFindBox",
"returns",
"a",
"Box",
"instance",
"for",
"given",
"name",
"like",
"FindBox",
"does",
".",
"It",
"does",
"not",
"return",
"an",
"error",
"instead",
"it",
"panics",
"when",
"an",
"error",
"occurs",
"."
] | c880e3cd4dd81db36b423e83dc0aeea4dca93774 | https://github.com/GeertJohan/go.rice/blob/c880e3cd4dd81db36b423e83dc0aeea4dca93774/box.go#L107-L113 | train |
GeertJohan/go.rice | box.go | String | func (b *Box) String(name string) (string, error) {
// check if box is embedded, optimized fast path
if b.IsEmbedded() {
// find file in embed
ef := b.embed.Files[name]
if ef == nil {
return "", os.ErrNotExist
}
// return as string
return ef.Content, nil
}
bts, err := b.Bytes(name)
if err != nil {
... | go | func (b *Box) String(name string) (string, error) {
// check if box is embedded, optimized fast path
if b.IsEmbedded() {
// find file in embed
ef := b.embed.Files[name]
if ef == nil {
return "", os.ErrNotExist
}
// return as string
return ef.Content, nil
}
bts, err := b.Bytes(name)
if err != nil {
... | [
"func",
"(",
"b",
"*",
"Box",
")",
"String",
"(",
"name",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"// check if box is embedded, optimized fast path",
"if",
"b",
".",
"IsEmbedded",
"(",
")",
"{",
"// find file in embed",
"ef",
":=",
"b",
".",
... | // String returns the content of the file with given name as string. | [
"String",
"returns",
"the",
"content",
"of",
"the",
"file",
"with",
"given",
"name",
"as",
"string",
"."
] | c880e3cd4dd81db36b423e83dc0aeea4dca93774 | https://github.com/GeertJohan/go.rice/blob/c880e3cd4dd81db36b423e83dc0aeea4dca93774/box.go#L305-L322 | train |
GeertJohan/go.rice | box.go | MustString | func (b *Box) MustString(name string) string {
str, err := b.String(name)
if err != nil {
panic(err)
}
return str
} | go | func (b *Box) MustString(name string) string {
str, err := b.String(name)
if err != nil {
panic(err)
}
return str
} | [
"func",
"(",
"b",
"*",
"Box",
")",
"MustString",
"(",
"name",
"string",
")",
"string",
"{",
"str",
",",
"err",
":=",
"b",
".",
"String",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",... | // MustString returns the content of the file with given name as string.
// panic's on error. | [
"MustString",
"returns",
"the",
"content",
"of",
"the",
"file",
"with",
"given",
"name",
"as",
"string",
".",
"panic",
"s",
"on",
"error",
"."
] | c880e3cd4dd81db36b423e83dc0aeea4dca93774 | https://github.com/GeertJohan/go.rice/blob/c880e3cd4dd81db36b423e83dc0aeea4dca93774/box.go#L326-L332 | train |
GeertJohan/go.rice | virtual.go | newVirtualFile | func newVirtualFile(ef *embedded.EmbeddedFile) *virtualFile {
vf := &virtualFile{
EmbeddedFile: ef,
offset: 0,
closed: false,
}
return vf
} | go | func newVirtualFile(ef *embedded.EmbeddedFile) *virtualFile {
vf := &virtualFile{
EmbeddedFile: ef,
offset: 0,
closed: false,
}
return vf
} | [
"func",
"newVirtualFile",
"(",
"ef",
"*",
"embedded",
".",
"EmbeddedFile",
")",
"*",
"virtualFile",
"{",
"vf",
":=",
"&",
"virtualFile",
"{",
"EmbeddedFile",
":",
"ef",
",",
"offset",
":",
"0",
",",
"closed",
":",
"false",
",",
"}",
"\n",
"return",
"vf... | // create a new virtualFile for given EmbeddedFile | [
"create",
"a",
"new",
"virtualFile",
"for",
"given",
"EmbeddedFile"
] | c880e3cd4dd81db36b423e83dc0aeea4dca93774 | https://github.com/GeertJohan/go.rice/blob/c880e3cd4dd81db36b423e83dc0aeea4dca93774/virtual.go#L25-L32 | train |
GeertJohan/go.rice | virtual.go | newVirtualDir | func newVirtualDir(ed *embedded.EmbeddedDir) *virtualDir {
vd := &virtualDir{
EmbeddedDir: ed,
offset: 0,
closed: false,
}
return vd
} | go | func newVirtualDir(ed *embedded.EmbeddedDir) *virtualDir {
vd := &virtualDir{
EmbeddedDir: ed,
offset: 0,
closed: false,
}
return vd
} | [
"func",
"newVirtualDir",
"(",
"ed",
"*",
"embedded",
".",
"EmbeddedDir",
")",
"*",
"virtualDir",
"{",
"vd",
":=",
"&",
"virtualDir",
"{",
"EmbeddedDir",
":",
"ed",
",",
"offset",
":",
"0",
",",
"closed",
":",
"false",
",",
"}",
"\n",
"return",
"vd",
... | // create a new virtualDir for given EmbeddedDir | [
"create",
"a",
"new",
"virtualDir",
"for",
"given",
"EmbeddedDir"
] | c880e3cd4dd81db36b423e83dc0aeea4dca93774 | https://github.com/GeertJohan/go.rice/blob/c880e3cd4dd81db36b423e83dc0aeea4dca93774/virtual.go#L150-L157 | train |
GeertJohan/go.rice | rice/util.go | generated | func generated(filename string) bool {
return filepath.Base(filename) == boxFilename ||
strings.HasSuffix(filename, "."+boxFilename) ||
strings.HasSuffix(filename, sysoBoxSuffix)
} | go | func generated(filename string) bool {
return filepath.Base(filename) == boxFilename ||
strings.HasSuffix(filename, "."+boxFilename) ||
strings.HasSuffix(filename, sysoBoxSuffix)
} | [
"func",
"generated",
"(",
"filename",
"string",
")",
"bool",
"{",
"return",
"filepath",
".",
"Base",
"(",
"filename",
")",
"==",
"boxFilename",
"||",
"strings",
".",
"HasSuffix",
"(",
"filename",
",",
"\"",
"\"",
"+",
"boxFilename",
")",
"||",
"strings",
... | // generated tests if a filename was generated by rice | [
"generated",
"tests",
"if",
"a",
"filename",
"was",
"generated",
"by",
"rice"
] | c880e3cd4dd81db36b423e83dc0aeea4dca93774 | https://github.com/GeertJohan/go.rice/blob/c880e3cd4dd81db36b423e83dc0aeea4dca93774/rice/util.go#L11-L15 | train |
GeertJohan/go.rice | rice/util.go | randomString | func randomString(length int) string {
rand.Seed(time.Now().UnixNano())
k := make([]rune, length)
for i := 0; i < length; i++ {
c := rand.Intn(35)
if c < 10 {
c += 48 // numbers (0-9) (0+48 == 48 == '0', 9+48 == 57 == '9')
} else {
c += 87 // lower case alphabets (a-z) (10+87 == 97 == 'a', 35+87 == 122 =... | go | func randomString(length int) string {
rand.Seed(time.Now().UnixNano())
k := make([]rune, length)
for i := 0; i < length; i++ {
c := rand.Intn(35)
if c < 10 {
c += 48 // numbers (0-9) (0+48 == 48 == '0', 9+48 == 57 == '9')
} else {
c += 87 // lower case alphabets (a-z) (10+87 == 97 == 'a', 35+87 == 122 =... | [
"func",
"randomString",
"(",
"length",
"int",
")",
"string",
"{",
"rand",
".",
"Seed",
"(",
"time",
".",
"Now",
"(",
")",
".",
"UnixNano",
"(",
")",
")",
"\n",
"k",
":=",
"make",
"(",
"[",
"]",
"rune",
",",
"length",
")",
"\n",
"for",
"i",
":="... | // randomString generates a pseudo-random alpha-numeric string with given length. | [
"randomString",
"generates",
"a",
"pseudo",
"-",
"random",
"alpha",
"-",
"numeric",
"string",
"with",
"given",
"length",
"."
] | c880e3cd4dd81db36b423e83dc0aeea4dca93774 | https://github.com/GeertJohan/go.rice/blob/c880e3cd4dd81db36b423e83dc0aeea4dca93774/rice/util.go#L18-L31 | train |
bwmarrin/discordgo | ratelimit.go | NewRatelimiter | func NewRatelimiter() *RateLimiter {
return &RateLimiter{
buckets: make(map[string]*Bucket),
global: new(int64),
customRateLimits: []*customRateLimit{
&customRateLimit{
suffix: "//reactions//",
requests: 1,
reset: 200 * time.Millisecond,
},
},
}
} | go | func NewRatelimiter() *RateLimiter {
return &RateLimiter{
buckets: make(map[string]*Bucket),
global: new(int64),
customRateLimits: []*customRateLimit{
&customRateLimit{
suffix: "//reactions//",
requests: 1,
reset: 200 * time.Millisecond,
},
},
}
} | [
"func",
"NewRatelimiter",
"(",
")",
"*",
"RateLimiter",
"{",
"return",
"&",
"RateLimiter",
"{",
"buckets",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"Bucket",
")",
",",
"global",
":",
"new",
"(",
"int64",
")",
",",
"customRateLimits",
":",
"[",... | // NewRatelimiter returns a new RateLimiter | [
"NewRatelimiter",
"returns",
"a",
"new",
"RateLimiter"
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/ratelimit.go#L29-L42 | train |
bwmarrin/discordgo | ratelimit.go | GetBucket | func (r *RateLimiter) GetBucket(key string) *Bucket {
r.Lock()
defer r.Unlock()
if bucket, ok := r.buckets[key]; ok {
return bucket
}
b := &Bucket{
Remaining: 1,
Key: key,
global: r.global,
}
// Check if there is a custom ratelimit set for this bucket ID.
for _, rl := range r.customRateLimit... | go | func (r *RateLimiter) GetBucket(key string) *Bucket {
r.Lock()
defer r.Unlock()
if bucket, ok := r.buckets[key]; ok {
return bucket
}
b := &Bucket{
Remaining: 1,
Key: key,
global: r.global,
}
// Check if there is a custom ratelimit set for this bucket ID.
for _, rl := range r.customRateLimit... | [
"func",
"(",
"r",
"*",
"RateLimiter",
")",
"GetBucket",
"(",
"key",
"string",
")",
"*",
"Bucket",
"{",
"r",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"bucket",
",",
"ok",
":=",
"r",
".",
"buckets",
"[",
"... | // GetBucket retrieves or creates a bucket | [
"GetBucket",
"retrieves",
"or",
"creates",
"a",
"bucket"
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/ratelimit.go#L45-L69 | train |
bwmarrin/discordgo | ratelimit.go | GetWaitTime | func (r *RateLimiter) GetWaitTime(b *Bucket, minRemaining int) time.Duration {
// If we ran out of calls and the reset time is still ahead of us
// then we need to take it easy and relax a little
if b.Remaining < minRemaining && b.reset.After(time.Now()) {
return b.reset.Sub(time.Now())
}
// Check for global ra... | go | func (r *RateLimiter) GetWaitTime(b *Bucket, minRemaining int) time.Duration {
// If we ran out of calls and the reset time is still ahead of us
// then we need to take it easy and relax a little
if b.Remaining < minRemaining && b.reset.After(time.Now()) {
return b.reset.Sub(time.Now())
}
// Check for global ra... | [
"func",
"(",
"r",
"*",
"RateLimiter",
")",
"GetWaitTime",
"(",
"b",
"*",
"Bucket",
",",
"minRemaining",
"int",
")",
"time",
".",
"Duration",
"{",
"// If we ran out of calls and the reset time is still ahead of us",
"// then we need to take it easy and relax a little",
"if",... | // GetWaitTime returns the duration you should wait for a Bucket | [
"GetWaitTime",
"returns",
"the",
"duration",
"you",
"should",
"wait",
"for",
"a",
"Bucket"
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/ratelimit.go#L72-L86 | train |
bwmarrin/discordgo | ratelimit.go | LockBucket | func (r *RateLimiter) LockBucket(bucketID string) *Bucket {
return r.LockBucketObject(r.GetBucket(bucketID))
} | go | func (r *RateLimiter) LockBucket(bucketID string) *Bucket {
return r.LockBucketObject(r.GetBucket(bucketID))
} | [
"func",
"(",
"r",
"*",
"RateLimiter",
")",
"LockBucket",
"(",
"bucketID",
"string",
")",
"*",
"Bucket",
"{",
"return",
"r",
".",
"LockBucketObject",
"(",
"r",
".",
"GetBucket",
"(",
"bucketID",
")",
")",
"\n",
"}"
] | // LockBucket Locks until a request can be made | [
"LockBucket",
"Locks",
"until",
"a",
"request",
"can",
"be",
"made"
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/ratelimit.go#L89-L91 | train |
bwmarrin/discordgo | ratelimit.go | LockBucketObject | func (r *RateLimiter) LockBucketObject(b *Bucket) *Bucket {
b.Lock()
if wait := r.GetWaitTime(b, 1); wait > 0 {
time.Sleep(wait)
}
b.Remaining--
return b
} | go | func (r *RateLimiter) LockBucketObject(b *Bucket) *Bucket {
b.Lock()
if wait := r.GetWaitTime(b, 1); wait > 0 {
time.Sleep(wait)
}
b.Remaining--
return b
} | [
"func",
"(",
"r",
"*",
"RateLimiter",
")",
"LockBucketObject",
"(",
"b",
"*",
"Bucket",
")",
"*",
"Bucket",
"{",
"b",
".",
"Lock",
"(",
")",
"\n\n",
"if",
"wait",
":=",
"r",
".",
"GetWaitTime",
"(",
"b",
",",
"1",
")",
";",
"wait",
">",
"0",
"{... | // LockBucketObject Locks an already resolved bucket until a request can be made | [
"LockBucketObject",
"Locks",
"an",
"already",
"resolved",
"bucket",
"until",
"a",
"request",
"can",
"be",
"made"
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/ratelimit.go#L94-L103 | train |
bwmarrin/discordgo | ratelimit.go | Release | func (b *Bucket) Release(headers http.Header) error {
defer b.Unlock()
// Check if the bucket uses a custom ratelimiter
if rl := b.customRateLimit; rl != nil {
if time.Now().Sub(b.lastReset) >= rl.reset {
b.Remaining = rl.requests - 1
b.lastReset = time.Now()
}
if b.Remaining < 1 {
b.reset = time.Now... | go | func (b *Bucket) Release(headers http.Header) error {
defer b.Unlock()
// Check if the bucket uses a custom ratelimiter
if rl := b.customRateLimit; rl != nil {
if time.Now().Sub(b.lastReset) >= rl.reset {
b.Remaining = rl.requests - 1
b.lastReset = time.Now()
}
if b.Remaining < 1 {
b.reset = time.Now... | [
"func",
"(",
"b",
"*",
"Bucket",
")",
"Release",
"(",
"headers",
"http",
".",
"Header",
")",
"error",
"{",
"defer",
"b",
".",
"Unlock",
"(",
")",
"\n\n",
"// Check if the bucket uses a custom ratelimiter",
"if",
"rl",
":=",
"b",
".",
"customRateLimit",
";",
... | // Release unlocks the bucket and reads the headers to update the buckets ratelimit info
// and locks up the whole thing in case if there's a global ratelimit. | [
"Release",
"unlocks",
"the",
"bucket",
"and",
"reads",
"the",
"headers",
"to",
"update",
"the",
"buckets",
"ratelimit",
"info",
"and",
"locks",
"up",
"the",
"whole",
"thing",
"in",
"case",
"if",
"there",
"s",
"a",
"global",
"ratelimit",
"."
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/ratelimit.go#L121-L194 | train |
bwmarrin/discordgo | state.go | NewState | func NewState() *State {
return &State{
Ready: Ready{
PrivateChannels: []*Channel{},
Guilds: []*Guild{},
},
TrackChannels: true,
TrackEmojis: true,
TrackMembers: true,
TrackRoles: true,
TrackVoice: true,
TrackPresences: true,
guildMap: make(map[string]*Guild),
cha... | go | func NewState() *State {
return &State{
Ready: Ready{
PrivateChannels: []*Channel{},
Guilds: []*Guild{},
},
TrackChannels: true,
TrackEmojis: true,
TrackMembers: true,
TrackRoles: true,
TrackVoice: true,
TrackPresences: true,
guildMap: make(map[string]*Guild),
cha... | [
"func",
"NewState",
"(",
")",
"*",
"State",
"{",
"return",
"&",
"State",
"{",
"Ready",
":",
"Ready",
"{",
"PrivateChannels",
":",
"[",
"]",
"*",
"Channel",
"{",
"}",
",",
"Guilds",
":",
"[",
"]",
"*",
"Guild",
"{",
"}",
",",
"}",
",",
"TrackChann... | // NewState creates an empty state. | [
"NewState",
"creates",
"an",
"empty",
"state",
"."
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/state.go#L50-L66 | train |
bwmarrin/discordgo | state.go | GuildAdd | func (s *State) GuildAdd(guild *Guild) error {
if s == nil {
return ErrNilState
}
s.Lock()
defer s.Unlock()
// Update the channels to point to the right guild, adding them to the channelMap as we go
for _, c := range guild.Channels {
s.channelMap[c.ID] = c
}
// If this guild contains a new member slice, ... | go | func (s *State) GuildAdd(guild *Guild) error {
if s == nil {
return ErrNilState
}
s.Lock()
defer s.Unlock()
// Update the channels to point to the right guild, adding them to the channelMap as we go
for _, c := range guild.Channels {
s.channelMap[c.ID] = c
}
// If this guild contains a new member slice, ... | [
"func",
"(",
"s",
"*",
"State",
")",
"GuildAdd",
"(",
"guild",
"*",
"Guild",
")",
"error",
"{",
"if",
"s",
"==",
"nil",
"{",
"return",
"ErrNilState",
"\n",
"}",
"\n\n",
"s",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"Unlock",
"(",
")",
"\... | // GuildAdd adds a guild to the current world state, or
// updates it if it already exists. | [
"GuildAdd",
"adds",
"a",
"guild",
"to",
"the",
"current",
"world",
"state",
"or",
"updates",
"it",
"if",
"it",
"already",
"exists",
"."
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/state.go#L78-L131 | train |
bwmarrin/discordgo | state.go | GuildRemove | func (s *State) GuildRemove(guild *Guild) error {
if s == nil {
return ErrNilState
}
_, err := s.Guild(guild.ID)
if err != nil {
return err
}
s.Lock()
defer s.Unlock()
delete(s.guildMap, guild.ID)
for i, g := range s.Guilds {
if g.ID == guild.ID {
s.Guilds = append(s.Guilds[:i], s.Guilds[i+1:]...)... | go | func (s *State) GuildRemove(guild *Guild) error {
if s == nil {
return ErrNilState
}
_, err := s.Guild(guild.ID)
if err != nil {
return err
}
s.Lock()
defer s.Unlock()
delete(s.guildMap, guild.ID)
for i, g := range s.Guilds {
if g.ID == guild.ID {
s.Guilds = append(s.Guilds[:i], s.Guilds[i+1:]...)... | [
"func",
"(",
"s",
"*",
"State",
")",
"GuildRemove",
"(",
"guild",
"*",
"Guild",
")",
"error",
"{",
"if",
"s",
"==",
"nil",
"{",
"return",
"ErrNilState",
"\n",
"}",
"\n\n",
"_",
",",
"err",
":=",
"s",
".",
"Guild",
"(",
"guild",
".",
"ID",
")",
... | // GuildRemove removes a guild from current world state. | [
"GuildRemove",
"removes",
"a",
"guild",
"from",
"current",
"world",
"state",
"."
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/state.go#L134-L157 | train |
bwmarrin/discordgo | state.go | Guild | func (s *State) Guild(guildID string) (*Guild, error) {
if s == nil {
return nil, ErrNilState
}
s.RLock()
defer s.RUnlock()
if g, ok := s.guildMap[guildID]; ok {
return g, nil
}
return nil, ErrStateNotFound
} | go | func (s *State) Guild(guildID string) (*Guild, error) {
if s == nil {
return nil, ErrNilState
}
s.RLock()
defer s.RUnlock()
if g, ok := s.guildMap[guildID]; ok {
return g, nil
}
return nil, ErrStateNotFound
} | [
"func",
"(",
"s",
"*",
"State",
")",
"Guild",
"(",
"guildID",
"string",
")",
"(",
"*",
"Guild",
",",
"error",
")",
"{",
"if",
"s",
"==",
"nil",
"{",
"return",
"nil",
",",
"ErrNilState",
"\n",
"}",
"\n\n",
"s",
".",
"RLock",
"(",
")",
"\n",
"def... | // Guild gets a guild by ID.
// Useful for querying if @me is in a guild:
// _, err := discordgo.Session.State.Guild(guildID)
// isInGuild := err == nil | [
"Guild",
"gets",
"a",
"guild",
"by",
"ID",
".",
"Useful",
"for",
"querying",
"if"
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/state.go#L163-L176 | train |
bwmarrin/discordgo | state.go | PresenceAdd | func (s *State) PresenceAdd(guildID string, presence *Presence) error {
if s == nil {
return ErrNilState
}
guild, err := s.Guild(guildID)
if err != nil {
return err
}
s.Lock()
defer s.Unlock()
for i, p := range guild.Presences {
if p.User.ID == presence.User.ID {
//guild.Presences[i] = presence
... | go | func (s *State) PresenceAdd(guildID string, presence *Presence) error {
if s == nil {
return ErrNilState
}
guild, err := s.Guild(guildID)
if err != nil {
return err
}
s.Lock()
defer s.Unlock()
for i, p := range guild.Presences {
if p.User.ID == presence.User.ID {
//guild.Presences[i] = presence
... | [
"func",
"(",
"s",
"*",
"State",
")",
"PresenceAdd",
"(",
"guildID",
"string",
",",
"presence",
"*",
"Presence",
")",
"error",
"{",
"if",
"s",
"==",
"nil",
"{",
"return",
"ErrNilState",
"\n",
"}",
"\n\n",
"guild",
",",
"err",
":=",
"s",
".",
"Guild",
... | // PresenceAdd adds a presence to the current world state, or
// updates it if it already exists. | [
"PresenceAdd",
"adds",
"a",
"presence",
"to",
"the",
"current",
"world",
"state",
"or",
"updates",
"it",
"if",
"it",
"already",
"exists",
"."
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/state.go#L180-L233 | train |
bwmarrin/discordgo | state.go | PresenceRemove | func (s *State) PresenceRemove(guildID string, presence *Presence) error {
if s == nil {
return ErrNilState
}
guild, err := s.Guild(guildID)
if err != nil {
return err
}
s.Lock()
defer s.Unlock()
for i, p := range guild.Presences {
if p.User.ID == presence.User.ID {
guild.Presences = append(guild.Pr... | go | func (s *State) PresenceRemove(guildID string, presence *Presence) error {
if s == nil {
return ErrNilState
}
guild, err := s.Guild(guildID)
if err != nil {
return err
}
s.Lock()
defer s.Unlock()
for i, p := range guild.Presences {
if p.User.ID == presence.User.ID {
guild.Presences = append(guild.Pr... | [
"func",
"(",
"s",
"*",
"State",
")",
"PresenceRemove",
"(",
"guildID",
"string",
",",
"presence",
"*",
"Presence",
")",
"error",
"{",
"if",
"s",
"==",
"nil",
"{",
"return",
"ErrNilState",
"\n",
"}",
"\n\n",
"guild",
",",
"err",
":=",
"s",
".",
"Guild... | // PresenceRemove removes a presence from the current world state. | [
"PresenceRemove",
"removes",
"a",
"presence",
"from",
"the",
"current",
"world",
"state",
"."
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/state.go#L236-L257 | train |
bwmarrin/discordgo | state.go | Presence | func (s *State) Presence(guildID, userID string) (*Presence, error) {
if s == nil {
return nil, ErrNilState
}
guild, err := s.Guild(guildID)
if err != nil {
return nil, err
}
for _, p := range guild.Presences {
if p.User.ID == userID {
return p, nil
}
}
return nil, ErrStateNotFound
} | go | func (s *State) Presence(guildID, userID string) (*Presence, error) {
if s == nil {
return nil, ErrNilState
}
guild, err := s.Guild(guildID)
if err != nil {
return nil, err
}
for _, p := range guild.Presences {
if p.User.ID == userID {
return p, nil
}
}
return nil, ErrStateNotFound
} | [
"func",
"(",
"s",
"*",
"State",
")",
"Presence",
"(",
"guildID",
",",
"userID",
"string",
")",
"(",
"*",
"Presence",
",",
"error",
")",
"{",
"if",
"s",
"==",
"nil",
"{",
"return",
"nil",
",",
"ErrNilState",
"\n",
"}",
"\n\n",
"guild",
",",
"err",
... | // Presence gets a presence by ID from a guild. | [
"Presence",
"gets",
"a",
"presence",
"by",
"ID",
"from",
"a",
"guild",
"."
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/state.go#L260-L277 | train |
bwmarrin/discordgo | state.go | MemberRemove | func (s *State) MemberRemove(member *Member) error {
if s == nil {
return ErrNilState
}
guild, err := s.Guild(member.GuildID)
if err != nil {
return err
}
s.Lock()
defer s.Unlock()
members, ok := s.memberMap[member.GuildID]
if !ok {
return ErrStateNotFound
}
_, ok = members[member.User.ID]
if !ok ... | go | func (s *State) MemberRemove(member *Member) error {
if s == nil {
return ErrNilState
}
guild, err := s.Guild(member.GuildID)
if err != nil {
return err
}
s.Lock()
defer s.Unlock()
members, ok := s.memberMap[member.GuildID]
if !ok {
return ErrStateNotFound
}
_, ok = members[member.User.ID]
if !ok ... | [
"func",
"(",
"s",
"*",
"State",
")",
"MemberRemove",
"(",
"member",
"*",
"Member",
")",
"error",
"{",
"if",
"s",
"==",
"nil",
"{",
"return",
"ErrNilState",
"\n",
"}",
"\n\n",
"guild",
",",
"err",
":=",
"s",
".",
"Guild",
"(",
"member",
".",
"GuildI... | // MemberRemove removes a member from current world state. | [
"MemberRemove",
"removes",
"a",
"member",
"from",
"current",
"world",
"state",
"."
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/state.go#L318-L350 | train |
bwmarrin/discordgo | state.go | Member | func (s *State) Member(guildID, userID string) (*Member, error) {
if s == nil {
return nil, ErrNilState
}
s.RLock()
defer s.RUnlock()
members, ok := s.memberMap[guildID]
if !ok {
return nil, ErrStateNotFound
}
m, ok := members[userID]
if ok {
return m, nil
}
return nil, ErrStateNotFound
} | go | func (s *State) Member(guildID, userID string) (*Member, error) {
if s == nil {
return nil, ErrNilState
}
s.RLock()
defer s.RUnlock()
members, ok := s.memberMap[guildID]
if !ok {
return nil, ErrStateNotFound
}
m, ok := members[userID]
if ok {
return m, nil
}
return nil, ErrStateNotFound
} | [
"func",
"(",
"s",
"*",
"State",
")",
"Member",
"(",
"guildID",
",",
"userID",
"string",
")",
"(",
"*",
"Member",
",",
"error",
")",
"{",
"if",
"s",
"==",
"nil",
"{",
"return",
"nil",
",",
"ErrNilState",
"\n",
"}",
"\n\n",
"s",
".",
"RLock",
"(",
... | // Member gets a member by ID from a guild. | [
"Member",
"gets",
"a",
"member",
"by",
"ID",
"from",
"a",
"guild",
"."
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/state.go#L353-L372 | train |
bwmarrin/discordgo | state.go | RoleAdd | func (s *State) RoleAdd(guildID string, role *Role) error {
if s == nil {
return ErrNilState
}
guild, err := s.Guild(guildID)
if err != nil {
return err
}
s.Lock()
defer s.Unlock()
for i, r := range guild.Roles {
if r.ID == role.ID {
guild.Roles[i] = role
return nil
}
}
guild.Roles = append(... | go | func (s *State) RoleAdd(guildID string, role *Role) error {
if s == nil {
return ErrNilState
}
guild, err := s.Guild(guildID)
if err != nil {
return err
}
s.Lock()
defer s.Unlock()
for i, r := range guild.Roles {
if r.ID == role.ID {
guild.Roles[i] = role
return nil
}
}
guild.Roles = append(... | [
"func",
"(",
"s",
"*",
"State",
")",
"RoleAdd",
"(",
"guildID",
"string",
",",
"role",
"*",
"Role",
")",
"error",
"{",
"if",
"s",
"==",
"nil",
"{",
"return",
"ErrNilState",
"\n",
"}",
"\n\n",
"guild",
",",
"err",
":=",
"s",
".",
"Guild",
"(",
"gu... | // RoleAdd adds a role to the current world state, or
// updates it if it already exists. | [
"RoleAdd",
"adds",
"a",
"role",
"to",
"the",
"current",
"world",
"state",
"or",
"updates",
"it",
"if",
"it",
"already",
"exists",
"."
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/state.go#L376-L398 | train |
bwmarrin/discordgo | state.go | RoleRemove | func (s *State) RoleRemove(guildID, roleID string) error {
if s == nil {
return ErrNilState
}
guild, err := s.Guild(guildID)
if err != nil {
return err
}
s.Lock()
defer s.Unlock()
for i, r := range guild.Roles {
if r.ID == roleID {
guild.Roles = append(guild.Roles[:i], guild.Roles[i+1:]...)
retur... | go | func (s *State) RoleRemove(guildID, roleID string) error {
if s == nil {
return ErrNilState
}
guild, err := s.Guild(guildID)
if err != nil {
return err
}
s.Lock()
defer s.Unlock()
for i, r := range guild.Roles {
if r.ID == roleID {
guild.Roles = append(guild.Roles[:i], guild.Roles[i+1:]...)
retur... | [
"func",
"(",
"s",
"*",
"State",
")",
"RoleRemove",
"(",
"guildID",
",",
"roleID",
"string",
")",
"error",
"{",
"if",
"s",
"==",
"nil",
"{",
"return",
"ErrNilState",
"\n",
"}",
"\n\n",
"guild",
",",
"err",
":=",
"s",
".",
"Guild",
"(",
"guildID",
")... | // RoleRemove removes a role from current world state by ID. | [
"RoleRemove",
"removes",
"a",
"role",
"from",
"current",
"world",
"state",
"by",
"ID",
"."
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/state.go#L401-L422 | train |
bwmarrin/discordgo | state.go | Role | func (s *State) Role(guildID, roleID string) (*Role, error) {
if s == nil {
return nil, ErrNilState
}
guild, err := s.Guild(guildID)
if err != nil {
return nil, err
}
s.RLock()
defer s.RUnlock()
for _, r := range guild.Roles {
if r.ID == roleID {
return r, nil
}
}
return nil, ErrStateNotFound
} | go | func (s *State) Role(guildID, roleID string) (*Role, error) {
if s == nil {
return nil, ErrNilState
}
guild, err := s.Guild(guildID)
if err != nil {
return nil, err
}
s.RLock()
defer s.RUnlock()
for _, r := range guild.Roles {
if r.ID == roleID {
return r, nil
}
}
return nil, ErrStateNotFound
} | [
"func",
"(",
"s",
"*",
"State",
")",
"Role",
"(",
"guildID",
",",
"roleID",
"string",
")",
"(",
"*",
"Role",
",",
"error",
")",
"{",
"if",
"s",
"==",
"nil",
"{",
"return",
"nil",
",",
"ErrNilState",
"\n",
"}",
"\n\n",
"guild",
",",
"err",
":=",
... | // Role gets a role by ID from a guild. | [
"Role",
"gets",
"a",
"role",
"by",
"ID",
"from",
"a",
"guild",
"."
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/state.go#L425-L445 | train |
bwmarrin/discordgo | state.go | ChannelAdd | func (s *State) ChannelAdd(channel *Channel) error {
if s == nil {
return ErrNilState
}
s.Lock()
defer s.Unlock()
// If the channel exists, replace it
if c, ok := s.channelMap[channel.ID]; ok {
if channel.Messages == nil {
channel.Messages = c.Messages
}
if channel.PermissionOverwrites == nil {
ch... | go | func (s *State) ChannelAdd(channel *Channel) error {
if s == nil {
return ErrNilState
}
s.Lock()
defer s.Unlock()
// If the channel exists, replace it
if c, ok := s.channelMap[channel.ID]; ok {
if channel.Messages == nil {
channel.Messages = c.Messages
}
if channel.PermissionOverwrites == nil {
ch... | [
"func",
"(",
"s",
"*",
"State",
")",
"ChannelAdd",
"(",
"channel",
"*",
"Channel",
")",
"error",
"{",
"if",
"s",
"==",
"nil",
"{",
"return",
"ErrNilState",
"\n",
"}",
"\n\n",
"s",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"Unlock",
"(",
")"... | // ChannelAdd adds a channel to the current world state, or
// updates it if it already exists.
// Channels may exist either as PrivateChannels or inside
// a guild. | [
"ChannelAdd",
"adds",
"a",
"channel",
"to",
"the",
"current",
"world",
"state",
"or",
"updates",
"it",
"if",
"it",
"already",
"exists",
".",
"Channels",
"may",
"exist",
"either",
"as",
"PrivateChannels",
"or",
"inside",
"a",
"guild",
"."
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/state.go#L451-L486 | train |
bwmarrin/discordgo | state.go | ChannelRemove | func (s *State) ChannelRemove(channel *Channel) error {
if s == nil {
return ErrNilState
}
_, err := s.Channel(channel.ID)
if err != nil {
return err
}
if channel.Type == ChannelTypeDM || channel.Type == ChannelTypeGroupDM {
s.Lock()
defer s.Unlock()
for i, c := range s.PrivateChannels {
if c.ID =... | go | func (s *State) ChannelRemove(channel *Channel) error {
if s == nil {
return ErrNilState
}
_, err := s.Channel(channel.ID)
if err != nil {
return err
}
if channel.Type == ChannelTypeDM || channel.Type == ChannelTypeGroupDM {
s.Lock()
defer s.Unlock()
for i, c := range s.PrivateChannels {
if c.ID =... | [
"func",
"(",
"s",
"*",
"State",
")",
"ChannelRemove",
"(",
"channel",
"*",
"Channel",
")",
"error",
"{",
"if",
"s",
"==",
"nil",
"{",
"return",
"ErrNilState",
"\n",
"}",
"\n\n",
"_",
",",
"err",
":=",
"s",
".",
"Channel",
"(",
"channel",
".",
"ID",... | // ChannelRemove removes a channel from current world state. | [
"ChannelRemove",
"removes",
"a",
"channel",
"from",
"current",
"world",
"state",
"."
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/state.go#L489-L529 | train |
bwmarrin/discordgo | state.go | Channel | func (s *State) Channel(channelID string) (*Channel, error) {
if s == nil {
return nil, ErrNilState
}
s.RLock()
defer s.RUnlock()
if c, ok := s.channelMap[channelID]; ok {
return c, nil
}
return nil, ErrStateNotFound
} | go | func (s *State) Channel(channelID string) (*Channel, error) {
if s == nil {
return nil, ErrNilState
}
s.RLock()
defer s.RUnlock()
if c, ok := s.channelMap[channelID]; ok {
return c, nil
}
return nil, ErrStateNotFound
} | [
"func",
"(",
"s",
"*",
"State",
")",
"Channel",
"(",
"channelID",
"string",
")",
"(",
"*",
"Channel",
",",
"error",
")",
"{",
"if",
"s",
"==",
"nil",
"{",
"return",
"nil",
",",
"ErrNilState",
"\n",
"}",
"\n\n",
"s",
".",
"RLock",
"(",
")",
"\n",
... | // Channel gets a channel by ID, it will look in all guilds and private channels. | [
"Channel",
"gets",
"a",
"channel",
"by",
"ID",
"it",
"will",
"look",
"in",
"all",
"guilds",
"and",
"private",
"channels",
"."
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/state.go#L544-L557 | train |
bwmarrin/discordgo | state.go | Emoji | func (s *State) Emoji(guildID, emojiID string) (*Emoji, error) {
if s == nil {
return nil, ErrNilState
}
guild, err := s.Guild(guildID)
if err != nil {
return nil, err
}
s.RLock()
defer s.RUnlock()
for _, e := range guild.Emojis {
if e.ID == emojiID {
return e, nil
}
}
return nil, ErrStateNotFo... | go | func (s *State) Emoji(guildID, emojiID string) (*Emoji, error) {
if s == nil {
return nil, ErrNilState
}
guild, err := s.Guild(guildID)
if err != nil {
return nil, err
}
s.RLock()
defer s.RUnlock()
for _, e := range guild.Emojis {
if e.ID == emojiID {
return e, nil
}
}
return nil, ErrStateNotFo... | [
"func",
"(",
"s",
"*",
"State",
")",
"Emoji",
"(",
"guildID",
",",
"emojiID",
"string",
")",
"(",
"*",
"Emoji",
",",
"error",
")",
"{",
"if",
"s",
"==",
"nil",
"{",
"return",
"nil",
",",
"ErrNilState",
"\n",
"}",
"\n\n",
"guild",
",",
"err",
":="... | // Emoji returns an emoji for a guild and emoji id. | [
"Emoji",
"returns",
"an",
"emoji",
"for",
"a",
"guild",
"and",
"emoji",
"id",
"."
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/state.go#L560-L580 | train |
bwmarrin/discordgo | state.go | EmojiAdd | func (s *State) EmojiAdd(guildID string, emoji *Emoji) error {
if s == nil {
return ErrNilState
}
guild, err := s.Guild(guildID)
if err != nil {
return err
}
s.Lock()
defer s.Unlock()
for i, e := range guild.Emojis {
if e.ID == emoji.ID {
guild.Emojis[i] = emoji
return nil
}
}
guild.Emojis =... | go | func (s *State) EmojiAdd(guildID string, emoji *Emoji) error {
if s == nil {
return ErrNilState
}
guild, err := s.Guild(guildID)
if err != nil {
return err
}
s.Lock()
defer s.Unlock()
for i, e := range guild.Emojis {
if e.ID == emoji.ID {
guild.Emojis[i] = emoji
return nil
}
}
guild.Emojis =... | [
"func",
"(",
"s",
"*",
"State",
")",
"EmojiAdd",
"(",
"guildID",
"string",
",",
"emoji",
"*",
"Emoji",
")",
"error",
"{",
"if",
"s",
"==",
"nil",
"{",
"return",
"ErrNilState",
"\n",
"}",
"\n\n",
"guild",
",",
"err",
":=",
"s",
".",
"Guild",
"(",
... | // EmojiAdd adds an emoji to the current world state. | [
"EmojiAdd",
"adds",
"an",
"emoji",
"to",
"the",
"current",
"world",
"state",
"."
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/state.go#L583-L605 | train |
bwmarrin/discordgo | state.go | EmojisAdd | func (s *State) EmojisAdd(guildID string, emojis []*Emoji) error {
for _, e := range emojis {
if err := s.EmojiAdd(guildID, e); err != nil {
return err
}
}
return nil
} | go | func (s *State) EmojisAdd(guildID string, emojis []*Emoji) error {
for _, e := range emojis {
if err := s.EmojiAdd(guildID, e); err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"s",
"*",
"State",
")",
"EmojisAdd",
"(",
"guildID",
"string",
",",
"emojis",
"[",
"]",
"*",
"Emoji",
")",
"error",
"{",
"for",
"_",
",",
"e",
":=",
"range",
"emojis",
"{",
"if",
"err",
":=",
"s",
".",
"EmojiAdd",
"(",
"guildID",
","... | // EmojisAdd adds multiple emojis to the world state. | [
"EmojisAdd",
"adds",
"multiple",
"emojis",
"to",
"the",
"world",
"state",
"."
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/state.go#L608-L615 | train |
bwmarrin/discordgo | state.go | MessageAdd | func (s *State) MessageAdd(message *Message) error {
if s == nil {
return ErrNilState
}
c, err := s.Channel(message.ChannelID)
if err != nil {
return err
}
s.Lock()
defer s.Unlock()
// If the message exists, merge in the new message contents.
for _, m := range c.Messages {
if m.ID == message.ID {
i... | go | func (s *State) MessageAdd(message *Message) error {
if s == nil {
return ErrNilState
}
c, err := s.Channel(message.ChannelID)
if err != nil {
return err
}
s.Lock()
defer s.Unlock()
// If the message exists, merge in the new message contents.
for _, m := range c.Messages {
if m.ID == message.ID {
i... | [
"func",
"(",
"s",
"*",
"State",
")",
"MessageAdd",
"(",
"message",
"*",
"Message",
")",
"error",
"{",
"if",
"s",
"==",
"nil",
"{",
"return",
"ErrNilState",
"\n",
"}",
"\n\n",
"c",
",",
"err",
":=",
"s",
".",
"Channel",
"(",
"message",
".",
"Channel... | // MessageAdd adds a message to the current world state, or updates it if it exists.
// If the channel cannot be found, the message is discarded.
// Messages are kept in state up to s.MaxMessageCount per channel. | [
"MessageAdd",
"adds",
"a",
"message",
"to",
"the",
"current",
"world",
"state",
"or",
"updates",
"it",
"if",
"it",
"exists",
".",
"If",
"the",
"channel",
"cannot",
"be",
"found",
"the",
"message",
"is",
"discarded",
".",
"Messages",
"are",
"kept",
"in",
... | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/state.go#L620-L668 | train |
bwmarrin/discordgo | state.go | MessageRemove | func (s *State) MessageRemove(message *Message) error {
if s == nil {
return ErrNilState
}
return s.messageRemoveByID(message.ChannelID, message.ID)
} | go | func (s *State) MessageRemove(message *Message) error {
if s == nil {
return ErrNilState
}
return s.messageRemoveByID(message.ChannelID, message.ID)
} | [
"func",
"(",
"s",
"*",
"State",
")",
"MessageRemove",
"(",
"message",
"*",
"Message",
")",
"error",
"{",
"if",
"s",
"==",
"nil",
"{",
"return",
"ErrNilState",
"\n",
"}",
"\n\n",
"return",
"s",
".",
"messageRemoveByID",
"(",
"message",
".",
"ChannelID",
... | // MessageRemove removes a message from the world state. | [
"MessageRemove",
"removes",
"a",
"message",
"from",
"the",
"world",
"state",
"."
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/state.go#L671-L677 | train |
bwmarrin/discordgo | state.go | messageRemoveByID | func (s *State) messageRemoveByID(channelID, messageID string) error {
c, err := s.Channel(channelID)
if err != nil {
return err
}
s.Lock()
defer s.Unlock()
for i, m := range c.Messages {
if m.ID == messageID {
c.Messages = append(c.Messages[:i], c.Messages[i+1:]...)
return nil
}
}
return ErrStat... | go | func (s *State) messageRemoveByID(channelID, messageID string) error {
c, err := s.Channel(channelID)
if err != nil {
return err
}
s.Lock()
defer s.Unlock()
for i, m := range c.Messages {
if m.ID == messageID {
c.Messages = append(c.Messages[:i], c.Messages[i+1:]...)
return nil
}
}
return ErrStat... | [
"func",
"(",
"s",
"*",
"State",
")",
"messageRemoveByID",
"(",
"channelID",
",",
"messageID",
"string",
")",
"error",
"{",
"c",
",",
"err",
":=",
"s",
".",
"Channel",
"(",
"channelID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
... | // messageRemoveByID removes a message by channelID and messageID from the world state. | [
"messageRemoveByID",
"removes",
"a",
"message",
"by",
"channelID",
"and",
"messageID",
"from",
"the",
"world",
"state",
"."
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/state.go#L680-L697 | train |
bwmarrin/discordgo | state.go | Message | func (s *State) Message(channelID, messageID string) (*Message, error) {
if s == nil {
return nil, ErrNilState
}
c, err := s.Channel(channelID)
if err != nil {
return nil, err
}
s.RLock()
defer s.RUnlock()
for _, m := range c.Messages {
if m.ID == messageID {
return m, nil
}
}
return nil, ErrSt... | go | func (s *State) Message(channelID, messageID string) (*Message, error) {
if s == nil {
return nil, ErrNilState
}
c, err := s.Channel(channelID)
if err != nil {
return nil, err
}
s.RLock()
defer s.RUnlock()
for _, m := range c.Messages {
if m.ID == messageID {
return m, nil
}
}
return nil, ErrSt... | [
"func",
"(",
"s",
"*",
"State",
")",
"Message",
"(",
"channelID",
",",
"messageID",
"string",
")",
"(",
"*",
"Message",
",",
"error",
")",
"{",
"if",
"s",
"==",
"nil",
"{",
"return",
"nil",
",",
"ErrNilState",
"\n",
"}",
"\n\n",
"c",
",",
"err",
... | // Message gets a message by channel and message ID. | [
"Message",
"gets",
"a",
"message",
"by",
"channel",
"and",
"message",
"ID",
"."
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/state.go#L731-L751 | train |
bwmarrin/discordgo | state.go | onReady | func (s *State) onReady(se *Session, r *Ready) (err error) {
if s == nil {
return ErrNilState
}
s.Lock()
defer s.Unlock()
// We must track at least the current user for Voice, even
// if state is disabled, store the bare essentials.
if !se.StateEnabled {
ready := Ready{
Version: r.Version,
SessionI... | go | func (s *State) onReady(se *Session, r *Ready) (err error) {
if s == nil {
return ErrNilState
}
s.Lock()
defer s.Unlock()
// We must track at least the current user for Voice, even
// if state is disabled, store the bare essentials.
if !se.StateEnabled {
ready := Ready{
Version: r.Version,
SessionI... | [
"func",
"(",
"s",
"*",
"State",
")",
"onReady",
"(",
"se",
"*",
"Session",
",",
"r",
"*",
"Ready",
")",
"(",
"err",
"error",
")",
"{",
"if",
"s",
"==",
"nil",
"{",
"return",
"ErrNilState",
"\n",
"}",
"\n\n",
"s",
".",
"Lock",
"(",
")",
"\n",
... | // OnReady takes a Ready event and updates all internal state. | [
"OnReady",
"takes",
"a",
"Ready",
"event",
"and",
"updates",
"all",
"internal",
"state",
"."
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/state.go#L754-L792 | train |
bwmarrin/discordgo | state.go | UserColor | func (s *State) UserColor(userID, channelID string) int {
if s == nil {
return 0
}
channel, err := s.Channel(channelID)
if err != nil {
return 0
}
guild, err := s.Guild(channel.GuildID)
if err != nil {
return 0
}
member, err := s.Member(guild.ID, userID)
if err != nil {
return 0
}
roles := Roles... | go | func (s *State) UserColor(userID, channelID string) int {
if s == nil {
return 0
}
channel, err := s.Channel(channelID)
if err != nil {
return 0
}
guild, err := s.Guild(channel.GuildID)
if err != nil {
return 0
}
member, err := s.Member(guild.ID, userID)
if err != nil {
return 0
}
roles := Roles... | [
"func",
"(",
"s",
"*",
"State",
")",
"UserColor",
"(",
"userID",
",",
"channelID",
"string",
")",
"int",
"{",
"if",
"s",
"==",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n\n",
"channel",
",",
"err",
":=",
"s",
".",
"Channel",
"(",
"channelID",
")",
... | // UserColor returns the color of a user in a channel.
// While colors are defined at a Guild level, determining for a channel is more useful in message handlers.
// 0 is returned in cases of error, which is the color of @everyone.
// userID : The ID of the user to calculate the color for.
// channelID : The ID of... | [
"UserColor",
"returns",
"the",
"color",
"of",
"a",
"user",
"in",
"a",
"channel",
".",
"While",
"colors",
"are",
"defined",
"at",
"a",
"Guild",
"level",
"determining",
"for",
"a",
"channel",
"is",
"more",
"useful",
"in",
"message",
"handlers",
".",
"0",
"... | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/state.go#L981-L1015 | train |
bwmarrin/discordgo | voice.go | ChangeChannel | func (v *VoiceConnection) ChangeChannel(channelID string, mute, deaf bool) (err error) {
v.log(LogInformational, "called")
data := voiceChannelJoinOp{4, voiceChannelJoinData{&v.GuildID, &channelID, mute, deaf}}
v.wsMutex.Lock()
err = v.session.wsConn.WriteJSON(data)
v.wsMutex.Unlock()
if err != nil {
return
... | go | func (v *VoiceConnection) ChangeChannel(channelID string, mute, deaf bool) (err error) {
v.log(LogInformational, "called")
data := voiceChannelJoinOp{4, voiceChannelJoinData{&v.GuildID, &channelID, mute, deaf}}
v.wsMutex.Lock()
err = v.session.wsConn.WriteJSON(data)
v.wsMutex.Unlock()
if err != nil {
return
... | [
"func",
"(",
"v",
"*",
"VoiceConnection",
")",
"ChangeChannel",
"(",
"channelID",
"string",
",",
"mute",
",",
"deaf",
"bool",
")",
"(",
"err",
"error",
")",
"{",
"v",
".",
"log",
"(",
"LogInformational",
",",
"\"",
"\"",
")",
"\n\n",
"data",
":=",
"v... | // ChangeChannel sends Discord a request to change channels within a Guild
// !!! NOTE !!! This function may be removed in favour of just using ChannelVoiceJoin | [
"ChangeChannel",
"sends",
"Discord",
"a",
"request",
"to",
"change",
"channels",
"within",
"a",
"Guild",
"!!!",
"NOTE",
"!!!",
"This",
"function",
"may",
"be",
"removed",
"in",
"favour",
"of",
"just",
"using",
"ChannelVoiceJoin"
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/voice.go#L118-L135 | train |
bwmarrin/discordgo | voice.go | Disconnect | func (v *VoiceConnection) Disconnect() (err error) {
// Send a OP4 with a nil channel to disconnect
if v.sessionID != "" {
data := voiceChannelJoinOp{4, voiceChannelJoinData{&v.GuildID, nil, true, true}}
v.session.wsMutex.Lock()
err = v.session.wsConn.WriteJSON(data)
v.session.wsMutex.Unlock()
v.sessionID ... | go | func (v *VoiceConnection) Disconnect() (err error) {
// Send a OP4 with a nil channel to disconnect
if v.sessionID != "" {
data := voiceChannelJoinOp{4, voiceChannelJoinData{&v.GuildID, nil, true, true}}
v.session.wsMutex.Lock()
err = v.session.wsConn.WriteJSON(data)
v.session.wsMutex.Unlock()
v.sessionID ... | [
"func",
"(",
"v",
"*",
"VoiceConnection",
")",
"Disconnect",
"(",
")",
"(",
"err",
"error",
")",
"{",
"// Send a OP4 with a nil channel to disconnect",
"if",
"v",
".",
"sessionID",
"!=",
"\"",
"\"",
"{",
"data",
":=",
"voiceChannelJoinOp",
"{",
"4",
",",
"vo... | // Disconnect disconnects from this voice channel and closes the websocket
// and udp connections to Discord. | [
"Disconnect",
"disconnects",
"from",
"this",
"voice",
"channel",
"and",
"closes",
"the",
"websocket",
"and",
"udp",
"connections",
"to",
"Discord",
"."
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/voice.go#L139-L160 | train |
bwmarrin/discordgo | voice.go | Close | func (v *VoiceConnection) Close() {
v.log(LogInformational, "called")
v.Lock()
defer v.Unlock()
v.Ready = false
v.speaking = false
if v.close != nil {
v.log(LogInformational, "closing v.close")
close(v.close)
v.close = nil
}
if v.udpConn != nil {
v.log(LogInformational, "closing udp")
err := v.ud... | go | func (v *VoiceConnection) Close() {
v.log(LogInformational, "called")
v.Lock()
defer v.Unlock()
v.Ready = false
v.speaking = false
if v.close != nil {
v.log(LogInformational, "closing v.close")
close(v.close)
v.close = nil
}
if v.udpConn != nil {
v.log(LogInformational, "closing udp")
err := v.ud... | [
"func",
"(",
"v",
"*",
"VoiceConnection",
")",
"Close",
"(",
")",
"{",
"v",
".",
"log",
"(",
"LogInformational",
",",
"\"",
"\"",
")",
"\n\n",
"v",
".",
"Lock",
"(",
")",
"\n",
"defer",
"v",
".",
"Unlock",
"(",
")",
"\n\n",
"v",
".",
"Ready",
"... | // Close closes the voice ws and udp connections | [
"Close",
"closes",
"the",
"voice",
"ws",
"and",
"udp",
"connections"
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/voice.go#L163-L211 | train |
bwmarrin/discordgo | voice.go | AddHandler | func (v *VoiceConnection) AddHandler(h VoiceSpeakingUpdateHandler) {
v.Lock()
defer v.Unlock()
v.voiceSpeakingUpdateHandlers = append(v.voiceSpeakingUpdateHandlers, h)
} | go | func (v *VoiceConnection) AddHandler(h VoiceSpeakingUpdateHandler) {
v.Lock()
defer v.Unlock()
v.voiceSpeakingUpdateHandlers = append(v.voiceSpeakingUpdateHandlers, h)
} | [
"func",
"(",
"v",
"*",
"VoiceConnection",
")",
"AddHandler",
"(",
"h",
"VoiceSpeakingUpdateHandler",
")",
"{",
"v",
".",
"Lock",
"(",
")",
"\n",
"defer",
"v",
".",
"Unlock",
"(",
")",
"\n\n",
"v",
".",
"voiceSpeakingUpdateHandlers",
"=",
"append",
"(",
"... | // AddHandler adds a Handler for VoiceSpeakingUpdate events. | [
"AddHandler",
"adds",
"a",
"Handler",
"for",
"VoiceSpeakingUpdate",
"events",
"."
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/voice.go#L214-L219 | train |
bwmarrin/discordgo | voice.go | waitUntilConnected | func (v *VoiceConnection) waitUntilConnected() error {
v.log(LogInformational, "called")
i := 0
for {
v.RLock()
ready := v.Ready
v.RUnlock()
if ready {
return nil
}
if i > 10 {
return fmt.Errorf("timeout waiting for voice")
}
time.Sleep(1 * time.Second)
i++
}
} | go | func (v *VoiceConnection) waitUntilConnected() error {
v.log(LogInformational, "called")
i := 0
for {
v.RLock()
ready := v.Ready
v.RUnlock()
if ready {
return nil
}
if i > 10 {
return fmt.Errorf("timeout waiting for voice")
}
time.Sleep(1 * time.Second)
i++
}
} | [
"func",
"(",
"v",
"*",
"VoiceConnection",
")",
"waitUntilConnected",
"(",
")",
"error",
"{",
"v",
".",
"log",
"(",
"LogInformational",
",",
"\"",
"\"",
")",
"\n\n",
"i",
":=",
"0",
"\n",
"for",
"{",
"v",
".",
"RLock",
"(",
")",
"\n",
"ready",
":=",... | // WaitUntilConnected waits for the Voice Connection to
// become ready, if it does not become ready it returns an err | [
"WaitUntilConnected",
"waits",
"for",
"the",
"Voice",
"Connection",
"to",
"become",
"ready",
"if",
"it",
"does",
"not",
"become",
"ready",
"it",
"returns",
"an",
"err"
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/voice.go#L250-L270 | train |
bwmarrin/discordgo | voice.go | open | func (v *VoiceConnection) open() (err error) {
v.log(LogInformational, "called")
v.Lock()
defer v.Unlock()
// Don't open a websocket if one is already open
if v.wsConn != nil {
v.log(LogWarning, "refusing to overwrite non-nil websocket")
return
}
// TODO temp? loop to wait for the SessionID
i := 0
for ... | go | func (v *VoiceConnection) open() (err error) {
v.log(LogInformational, "called")
v.Lock()
defer v.Unlock()
// Don't open a websocket if one is already open
if v.wsConn != nil {
v.log(LogWarning, "refusing to overwrite non-nil websocket")
return
}
// TODO temp? loop to wait for the SessionID
i := 0
for ... | [
"func",
"(",
"v",
"*",
"VoiceConnection",
")",
"open",
"(",
")",
"(",
"err",
"error",
")",
"{",
"v",
".",
"log",
"(",
"LogInformational",
",",
"\"",
"\"",
")",
"\n\n",
"v",
".",
"Lock",
"(",
")",
"\n",
"defer",
"v",
".",
"Unlock",
"(",
")",
"\n... | // Open opens a voice connection. This should be called
// after VoiceChannelJoin is used and the data VOICE websocket events
// are captured. | [
"Open",
"opens",
"a",
"voice",
"connection",
".",
"This",
"should",
"be",
"called",
"after",
"VoiceChannelJoin",
"is",
"used",
"and",
"the",
"data",
"VOICE",
"websocket",
"events",
"are",
"captured",
"."
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/voice.go#L275-L337 | train |
bwmarrin/discordgo | voice.go | wsListen | func (v *VoiceConnection) wsListen(wsConn *websocket.Conn, close <-chan struct{}) {
v.log(LogInformational, "called")
for {
_, message, err := v.wsConn.ReadMessage()
if err != nil {
// Detect if we have been closed manually. If a Close() has already
// happened, the websocket we are listening on will be d... | go | func (v *VoiceConnection) wsListen(wsConn *websocket.Conn, close <-chan struct{}) {
v.log(LogInformational, "called")
for {
_, message, err := v.wsConn.ReadMessage()
if err != nil {
// Detect if we have been closed manually. If a Close() has already
// happened, the websocket we are listening on will be d... | [
"func",
"(",
"v",
"*",
"VoiceConnection",
")",
"wsListen",
"(",
"wsConn",
"*",
"websocket",
".",
"Conn",
",",
"close",
"<-",
"chan",
"struct",
"{",
"}",
")",
"{",
"v",
".",
"log",
"(",
"LogInformational",
",",
"\"",
"\"",
")",
"\n\n",
"for",
"{",
"... | // wsListen listens on the voice websocket for messages and passes them
// to the voice event handler. This is automatically called by the Open func | [
"wsListen",
"listens",
"on",
"the",
"voice",
"websocket",
"for",
"messages",
"and",
"passes",
"them",
"to",
"the",
"voice",
"event",
"handler",
".",
"This",
"is",
"automatically",
"called",
"by",
"the",
"Open",
"func"
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/voice.go#L341-L372 | train |
bwmarrin/discordgo | voice.go | udpOpen | func (v *VoiceConnection) udpOpen() (err error) {
v.Lock()
defer v.Unlock()
if v.wsConn == nil {
return fmt.Errorf("nil voice websocket")
}
if v.udpConn != nil {
return fmt.Errorf("udp connection already open")
}
if v.close == nil {
return fmt.Errorf("nil close channel")
}
if v.endpoint == "" {
re... | go | func (v *VoiceConnection) udpOpen() (err error) {
v.Lock()
defer v.Unlock()
if v.wsConn == nil {
return fmt.Errorf("nil voice websocket")
}
if v.udpConn != nil {
return fmt.Errorf("udp connection already open")
}
if v.close == nil {
return fmt.Errorf("nil close channel")
}
if v.endpoint == "" {
re... | [
"func",
"(",
"v",
"*",
"VoiceConnection",
")",
"udpOpen",
"(",
")",
"(",
"err",
"error",
")",
"{",
"v",
".",
"Lock",
"(",
")",
"\n",
"defer",
"v",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"v",
".",
"wsConn",
"==",
"nil",
"{",
"return",
"fmt",
"."... | // udpOpen opens a UDP connection to the voice server and completes the
// initial required handshake. This connection is left open in the session
// and can be used to send or receive audio. This should only be called
// from voice.wsEvent OP2 | [
"udpOpen",
"opens",
"a",
"UDP",
"connection",
"to",
"the",
"voice",
"server",
"and",
"completes",
"the",
"initial",
"required",
"handshake",
".",
"This",
"connection",
"is",
"left",
"open",
"in",
"the",
"session",
"and",
"can",
"be",
"used",
"to",
"send",
... | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/voice.go#L524-L615 | train |
bwmarrin/discordgo | voice.go | udpKeepAlive | func (v *VoiceConnection) udpKeepAlive(udpConn *net.UDPConn, close <-chan struct{}, i time.Duration) {
if udpConn == nil || close == nil {
return
}
var err error
var sequence uint64
packet := make([]byte, 8)
ticker := time.NewTicker(i)
defer ticker.Stop()
for {
binary.LittleEndian.PutUint64(packet, seq... | go | func (v *VoiceConnection) udpKeepAlive(udpConn *net.UDPConn, close <-chan struct{}, i time.Duration) {
if udpConn == nil || close == nil {
return
}
var err error
var sequence uint64
packet := make([]byte, 8)
ticker := time.NewTicker(i)
defer ticker.Stop()
for {
binary.LittleEndian.PutUint64(packet, seq... | [
"func",
"(",
"v",
"*",
"VoiceConnection",
")",
"udpKeepAlive",
"(",
"udpConn",
"*",
"net",
".",
"UDPConn",
",",
"close",
"<-",
"chan",
"struct",
"{",
"}",
",",
"i",
"time",
".",
"Duration",
")",
"{",
"if",
"udpConn",
"==",
"nil",
"||",
"close",
"==",... | // udpKeepAlive sends a udp packet to keep the udp connection open
// This is still a bit of a "proof of concept" | [
"udpKeepAlive",
"sends",
"a",
"udp",
"packet",
"to",
"keep",
"the",
"udp",
"connection",
"open",
"This",
"is",
"still",
"a",
"bit",
"of",
"a",
"proof",
"of",
"concept"
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/voice.go#L619-L650 | train |
bwmarrin/discordgo | voice.go | opusSender | func (v *VoiceConnection) opusSender(udpConn *net.UDPConn, close <-chan struct{}, opus <-chan []byte, rate, size int) {
if udpConn == nil || close == nil {
return
}
// VoiceConnection is now ready to receive audio packets
// TODO: this needs reviewed as I think there must be a better way.
v.Lock()
v.Ready = t... | go | func (v *VoiceConnection) opusSender(udpConn *net.UDPConn, close <-chan struct{}, opus <-chan []byte, rate, size int) {
if udpConn == nil || close == nil {
return
}
// VoiceConnection is now ready to receive audio packets
// TODO: this needs reviewed as I think there must be a better way.
v.Lock()
v.Ready = t... | [
"func",
"(",
"v",
"*",
"VoiceConnection",
")",
"opusSender",
"(",
"udpConn",
"*",
"net",
".",
"UDPConn",
",",
"close",
"<-",
"chan",
"struct",
"{",
"}",
",",
"opus",
"<-",
"chan",
"[",
"]",
"byte",
",",
"rate",
",",
"size",
"int",
")",
"{",
"if",
... | // opusSender will listen on the given channel and send any
// pre-encoded opus audio to Discord. Supposedly. | [
"opusSender",
"will",
"listen",
"on",
"the",
"given",
"channel",
"and",
"send",
"any",
"pre",
"-",
"encoded",
"opus",
"audio",
"to",
"Discord",
".",
"Supposedly",
"."
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/voice.go#L654-L747 | train |
bwmarrin/discordgo | structs.go | MessageFormat | func (e *Emoji) MessageFormat() string {
if e.ID != "" && e.Name != "" {
if e.Animated {
return "<a:" + e.APIName() + ">"
}
return "<:" + e.APIName() + ">"
}
return e.APIName()
} | go | func (e *Emoji) MessageFormat() string {
if e.ID != "" && e.Name != "" {
if e.Animated {
return "<a:" + e.APIName() + ">"
}
return "<:" + e.APIName() + ">"
}
return e.APIName()
} | [
"func",
"(",
"e",
"*",
"Emoji",
")",
"MessageFormat",
"(",
")",
"string",
"{",
"if",
"e",
".",
"ID",
"!=",
"\"",
"\"",
"&&",
"e",
".",
"Name",
"!=",
"\"",
"\"",
"{",
"if",
"e",
".",
"Animated",
"{",
"return",
"\"",
"\"",
"+",
"e",
".",
"APINa... | // MessageFormat returns a correctly formatted Emoji for use in Message content and embeds | [
"MessageFormat",
"returns",
"a",
"correctly",
"formatted",
"Emoji",
"for",
"use",
"in",
"Message",
"content",
"and",
"embeds"
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/structs.go#L289-L299 | train |
bwmarrin/discordgo | structs.go | APIName | func (e *Emoji) APIName() string {
if e.ID != "" && e.Name != "" {
return e.Name + ":" + e.ID
}
if e.Name != "" {
return e.Name
}
return e.ID
} | go | func (e *Emoji) APIName() string {
if e.ID != "" && e.Name != "" {
return e.Name + ":" + e.ID
}
if e.Name != "" {
return e.Name
}
return e.ID
} | [
"func",
"(",
"e",
"*",
"Emoji",
")",
"APIName",
"(",
")",
"string",
"{",
"if",
"e",
".",
"ID",
"!=",
"\"",
"\"",
"&&",
"e",
".",
"Name",
"!=",
"\"",
"\"",
"{",
"return",
"e",
".",
"Name",
"+",
"\"",
"\"",
"+",
"e",
".",
"ID",
"\n",
"}",
"... | // APIName returns an correctly formatted API name for use in the MessageReactions endpoints. | [
"APIName",
"returns",
"an",
"correctly",
"formatted",
"API",
"name",
"for",
"use",
"in",
"the",
"MessageReactions",
"endpoints",
"."
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/structs.go#L302-L310 | train |
bwmarrin/discordgo | structs.go | UnmarshalJSON | func (t *TimeStamps) UnmarshalJSON(b []byte) error {
temp := struct {
End float64 `json:"end,omitempty"`
Start float64 `json:"start,omitempty"`
}{}
err := json.Unmarshal(b, &temp)
if err != nil {
return err
}
t.EndTimestamp = int64(temp.End)
t.StartTimestamp = int64(temp.Start)
return nil
} | go | func (t *TimeStamps) UnmarshalJSON(b []byte) error {
temp := struct {
End float64 `json:"end,omitempty"`
Start float64 `json:"start,omitempty"`
}{}
err := json.Unmarshal(b, &temp)
if err != nil {
return err
}
t.EndTimestamp = int64(temp.End)
t.StartTimestamp = int64(temp.Start)
return nil
} | [
"func",
"(",
"t",
"*",
"TimeStamps",
")",
"UnmarshalJSON",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"temp",
":=",
"struct",
"{",
"End",
"float64",
"`json:\"end,omitempty\"`",
"\n",
"Start",
"float64",
"`json:\"start,omitempty\"`",
"\n",
"}",
"{",
"}",
... | // UnmarshalJSON unmarshals JSON into TimeStamps struct | [
"UnmarshalJSON",
"unmarshals",
"JSON",
"into",
"TimeStamps",
"struct"
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/structs.go#L575-L587 | train |
bwmarrin/discordgo | restapi.go | Request | func (s *Session) Request(method, urlStr string, data interface{}) (response []byte, err error) {
return s.RequestWithBucketID(method, urlStr, data, strings.SplitN(urlStr, "?", 2)[0])
} | go | func (s *Session) Request(method, urlStr string, data interface{}) (response []byte, err error) {
return s.RequestWithBucketID(method, urlStr, data, strings.SplitN(urlStr, "?", 2)[0])
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"Request",
"(",
"method",
",",
"urlStr",
"string",
",",
"data",
"interface",
"{",
"}",
")",
"(",
"response",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"return",
"s",
".",
"RequestWithBucketID",
"(",
"meth... | // Request is the same as RequestWithBucketID but the bucket id is the same as the urlStr | [
"Request",
"is",
"the",
"same",
"as",
"RequestWithBucketID",
"but",
"the",
"bucket",
"id",
"is",
"the",
"same",
"as",
"the",
"urlStr"
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/restapi.go#L45-L47 | train |
bwmarrin/discordgo | restapi.go | RequestWithLockedBucket | func (s *Session) RequestWithLockedBucket(method, urlStr, contentType string, b []byte, bucket *Bucket, sequence int) (response []byte, err error) {
if s.Debug {
log.Printf("API REQUEST %8s :: %s\n", method, urlStr)
log.Printf("API REQUEST PAYLOAD :: [%s]\n", string(b))
}
req, err := http.NewRequest(method, ur... | go | func (s *Session) RequestWithLockedBucket(method, urlStr, contentType string, b []byte, bucket *Bucket, sequence int) (response []byte, err error) {
if s.Debug {
log.Printf("API REQUEST %8s :: %s\n", method, urlStr)
log.Printf("API REQUEST PAYLOAD :: [%s]\n", string(b))
}
req, err := http.NewRequest(method, ur... | [
"func",
"(",
"s",
"*",
"Session",
")",
"RequestWithLockedBucket",
"(",
"method",
",",
"urlStr",
",",
"contentType",
"string",
",",
"b",
"[",
"]",
"byte",
",",
"bucket",
"*",
"Bucket",
",",
"sequence",
"int",
")",
"(",
"response",
"[",
"]",
"byte",
",",... | // RequestWithLockedBucket makes a request using a bucket that's already been locked | [
"RequestWithLockedBucket",
"makes",
"a",
"request",
"using",
"a",
"bucket",
"that",
"s",
"already",
"been",
"locked"
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/restapi.go#L73-L171 | train |
bwmarrin/discordgo | restapi.go | Register | func (s *Session) Register(username string) (token string, err error) {
data := struct {
Username string `json:"username"`
}{username}
response, err := s.RequestWithBucketID("POST", EndpointRegister, data, EndpointRegister)
if err != nil {
return
}
temp := struct {
Token string `json:"token"`
}{}
err ... | go | func (s *Session) Register(username string) (token string, err error) {
data := struct {
Username string `json:"username"`
}{username}
response, err := s.RequestWithBucketID("POST", EndpointRegister, data, EndpointRegister)
if err != nil {
return
}
temp := struct {
Token string `json:"token"`
}{}
err ... | [
"func",
"(",
"s",
"*",
"Session",
")",
"Register",
"(",
"username",
"string",
")",
"(",
"token",
"string",
",",
"err",
"error",
")",
"{",
"data",
":=",
"struct",
"{",
"Username",
"string",
"`json:\"username\"`",
"\n",
"}",
"{",
"username",
"}",
"\n\n",
... | // Register sends a Register request to Discord, and returns the authentication token
// Note that this account is temporary and should be verified for future use.
// Another option is to save the authentication token external, but this isn't recommended. | [
"Register",
"sends",
"a",
"Register",
"request",
"to",
"Discord",
"and",
"returns",
"the",
"authentication",
"token",
"Note",
"that",
"this",
"account",
"is",
"temporary",
"and",
"should",
"be",
"verified",
"for",
"future",
"use",
".",
"Another",
"option",
"is... | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/restapi.go#L223-L245 | train |
bwmarrin/discordgo | restapi.go | Logout | func (s *Session) Logout() (err error) {
// _, err = s.Request("POST", LOGOUT, `{"token": "` + s.Token + `"}`)
if s.Token == "" {
return
}
data := struct {
Token string `json:"token"`
}{s.Token}
_, err = s.RequestWithBucketID("POST", EndpointLogout, data, EndpointLogout)
return
} | go | func (s *Session) Logout() (err error) {
// _, err = s.Request("POST", LOGOUT, `{"token": "` + s.Token + `"}`)
if s.Token == "" {
return
}
data := struct {
Token string `json:"token"`
}{s.Token}
_, err = s.RequestWithBucketID("POST", EndpointLogout, data, EndpointLogout)
return
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"Logout",
"(",
")",
"(",
"err",
"error",
")",
"{",
"// _, err = s.Request(\"POST\", LOGOUT, `{\"token\": \"` + s.Token + `\"}`)",
"if",
"s",
".",
"Token",
"==",
"\"",
"\"",
"{",
"return",
"\n",
"}",
"\n\n",
"data",
":=",... | // Logout sends a logout request to Discord.
// This does not seem to actually invalidate the token. So you can still
// make API calls even after a Logout. So, it seems almost pointless to
// even use. | [
"Logout",
"sends",
"a",
"logout",
"request",
"to",
"Discord",
".",
"This",
"does",
"not",
"seem",
"to",
"actually",
"invalidate",
"the",
"token",
".",
"So",
"you",
"can",
"still",
"make",
"API",
"calls",
"even",
"after",
"a",
"Logout",
".",
"So",
"it",
... | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/restapi.go#L251-L265 | train |
bwmarrin/discordgo | restapi.go | UserUpdate | func (s *Session) UserUpdate(email, password, username, avatar, newPassword string) (st *User, err error) {
// NOTE: Avatar must be either the hash/id of existing Avatar or
// data:image/png;base64,BASE64_STRING_OF_NEW_AVATAR_PNG
// to set a new avatar.
// If left blank, avatar will be set to null/blank
data := ... | go | func (s *Session) UserUpdate(email, password, username, avatar, newPassword string) (st *User, err error) {
// NOTE: Avatar must be either the hash/id of existing Avatar or
// data:image/png;base64,BASE64_STRING_OF_NEW_AVATAR_PNG
// to set a new avatar.
// If left blank, avatar will be set to null/blank
data := ... | [
"func",
"(",
"s",
"*",
"Session",
")",
"UserUpdate",
"(",
"email",
",",
"password",
",",
"username",
",",
"avatar",
",",
"newPassword",
"string",
")",
"(",
"st",
"*",
"User",
",",
"err",
"error",
")",
"{",
"// NOTE: Avatar must be either the hash/id of existin... | // UserUpdate updates a users settings. | [
"UserUpdate",
"updates",
"a",
"users",
"settings",
"."
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/restapi.go#L308-L330 | train |
bwmarrin/discordgo | restapi.go | UserSettings | func (s *Session) UserSettings() (st *Settings, err error) {
body, err := s.RequestWithBucketID("GET", EndpointUserSettings("@me"), nil, EndpointUserSettings(""))
if err != nil {
return
}
err = unmarshal(body, &st)
return
} | go | func (s *Session) UserSettings() (st *Settings, err error) {
body, err := s.RequestWithBucketID("GET", EndpointUserSettings("@me"), nil, EndpointUserSettings(""))
if err != nil {
return
}
err = unmarshal(body, &st)
return
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"UserSettings",
"(",
")",
"(",
"st",
"*",
"Settings",
",",
"err",
"error",
")",
"{",
"body",
",",
"err",
":=",
"s",
".",
"RequestWithBucketID",
"(",
"\"",
"\"",
",",
"EndpointUserSettings",
"(",
"\"",
"\"",
")",... | // UserSettings returns the settings for a given user | [
"UserSettings",
"returns",
"the",
"settings",
"for",
"a",
"given",
"user"
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/restapi.go#L333-L342 | train |
bwmarrin/discordgo | restapi.go | UserConnections | func (s *Session) UserConnections() (conn []*UserConnection, err error) {
response, err := s.RequestWithBucketID("GET", EndpointUserConnections("@me"), nil, EndpointUserConnections("@me"))
if err != nil {
return nil, err
}
err = unmarshal(response, &conn)
if err != nil {
return
}
return
} | go | func (s *Session) UserConnections() (conn []*UserConnection, err error) {
response, err := s.RequestWithBucketID("GET", EndpointUserConnections("@me"), nil, EndpointUserConnections("@me"))
if err != nil {
return nil, err
}
err = unmarshal(response, &conn)
if err != nil {
return
}
return
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"UserConnections",
"(",
")",
"(",
"conn",
"[",
"]",
"*",
"UserConnection",
",",
"err",
"error",
")",
"{",
"response",
",",
"err",
":=",
"s",
".",
"RequestWithBucketID",
"(",
"\"",
"\"",
",",
"EndpointUserConnections... | // UserConnections returns the user's connections | [
"UserConnections",
"returns",
"the",
"user",
"s",
"connections"
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/restapi.go#L366-L378 | train |
bwmarrin/discordgo | restapi.go | UserChannels | func (s *Session) UserChannels() (st []*Channel, err error) {
body, err := s.RequestWithBucketID("GET", EndpointUserChannels("@me"), nil, EndpointUserChannels(""))
if err != nil {
return
}
err = unmarshal(body, &st)
return
} | go | func (s *Session) UserChannels() (st []*Channel, err error) {
body, err := s.RequestWithBucketID("GET", EndpointUserChannels("@me"), nil, EndpointUserChannels(""))
if err != nil {
return
}
err = unmarshal(body, &st)
return
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"UserChannels",
"(",
")",
"(",
"st",
"[",
"]",
"*",
"Channel",
",",
"err",
"error",
")",
"{",
"body",
",",
"err",
":=",
"s",
".",
"RequestWithBucketID",
"(",
"\"",
"\"",
",",
"EndpointUserChannels",
"(",
"\"",
... | // UserChannels returns an array of Channel structures for all private
// channels. | [
"UserChannels",
"returns",
"an",
"array",
"of",
"Channel",
"structures",
"for",
"all",
"private",
"channels",
"."
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/restapi.go#L382-L391 | train |
bwmarrin/discordgo | restapi.go | ChannelMessageEditComplex | func (s *Session) ChannelMessageEditComplex(m *MessageEdit) (st *Message, err error) {
if m.Embed != nil && m.Embed.Type == "" {
m.Embed.Type = "rich"
}
response, err := s.RequestWithBucketID("PATCH", EndpointChannelMessage(m.Channel, m.ID), m, EndpointChannelMessage(m.Channel, ""))
if err != nil {
return
}
... | go | func (s *Session) ChannelMessageEditComplex(m *MessageEdit) (st *Message, err error) {
if m.Embed != nil && m.Embed.Type == "" {
m.Embed.Type = "rich"
}
response, err := s.RequestWithBucketID("PATCH", EndpointChannelMessage(m.Channel, m.ID), m, EndpointChannelMessage(m.Channel, ""))
if err != nil {
return
}
... | [
"func",
"(",
"s",
"*",
"Session",
")",
"ChannelMessageEditComplex",
"(",
"m",
"*",
"MessageEdit",
")",
"(",
"st",
"*",
"Message",
",",
"err",
"error",
")",
"{",
"if",
"m",
".",
"Embed",
"!=",
"nil",
"&&",
"m",
".",
"Embed",
".",
"Type",
"==",
"\"",... | // ChannelMessageEditComplex edits an existing message, replacing it entirely with
// the given MessageEdit struct | [
"ChannelMessageEditComplex",
"edits",
"an",
"existing",
"message",
"replacing",
"it",
"entirely",
"with",
"the",
"given",
"MessageEdit",
"struct"
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/restapi.go#L1615-L1627 | train |
bwmarrin/discordgo | restapi.go | ChannelMessageDelete | func (s *Session) ChannelMessageDelete(channelID, messageID string) (err error) {
_, err = s.RequestWithBucketID("DELETE", EndpointChannelMessage(channelID, messageID), nil, EndpointChannelMessage(channelID, ""))
return
} | go | func (s *Session) ChannelMessageDelete(channelID, messageID string) (err error) {
_, err = s.RequestWithBucketID("DELETE", EndpointChannelMessage(channelID, messageID), nil, EndpointChannelMessage(channelID, ""))
return
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"ChannelMessageDelete",
"(",
"channelID",
",",
"messageID",
"string",
")",
"(",
"err",
"error",
")",
"{",
"_",
",",
"err",
"=",
"s",
".",
"RequestWithBucketID",
"(",
"\"",
"\"",
",",
"EndpointChannelMessage",
"(",
"... | // ChannelMessageDelete deletes a message from the Channel. | [
"ChannelMessageDelete",
"deletes",
"a",
"message",
"from",
"the",
"Channel",
"."
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/restapi.go#L1638-L1642 | train |
bwmarrin/discordgo | restapi.go | VoiceICE | func (s *Session) VoiceICE() (st *VoiceICE, err error) {
body, err := s.RequestWithBucketID("GET", EndpointVoiceIce, nil, EndpointVoiceIce)
if err != nil {
return
}
err = unmarshal(body, &st)
return
} | go | func (s *Session) VoiceICE() (st *VoiceICE, err error) {
body, err := s.RequestWithBucketID("GET", EndpointVoiceIce, nil, EndpointVoiceIce)
if err != nil {
return
}
err = unmarshal(body, &st)
return
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"VoiceICE",
"(",
")",
"(",
"st",
"*",
"VoiceICE",
",",
"err",
"error",
")",
"{",
"body",
",",
"err",
":=",
"s",
".",
"RequestWithBucketID",
"(",
"\"",
"\"",
",",
"EndpointVoiceIce",
",",
"nil",
",",
"EndpointVoi... | // VoiceICE returns the voice server ICE information | [
"VoiceICE",
"returns",
"the",
"voice",
"server",
"ICE",
"information"
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/restapi.go#L1854-L1863 | train |
bwmarrin/discordgo | restapi.go | GatewayBot | func (s *Session) GatewayBot() (st *GatewayBotResponse, err error) {
response, err := s.RequestWithBucketID("GET", EndpointGatewayBot, nil, EndpointGatewayBot)
if err != nil {
return
}
err = unmarshal(response, &st)
if err != nil {
return
}
// Ensure the gateway always has a trailing slash.
// MacOS will... | go | func (s *Session) GatewayBot() (st *GatewayBotResponse, err error) {
response, err := s.RequestWithBucketID("GET", EndpointGatewayBot, nil, EndpointGatewayBot)
if err != nil {
return
}
err = unmarshal(response, &st)
if err != nil {
return
}
// Ensure the gateway always has a trailing slash.
// MacOS will... | [
"func",
"(",
"s",
"*",
"Session",
")",
"GatewayBot",
"(",
")",
"(",
"st",
"*",
"GatewayBotResponse",
",",
"err",
"error",
")",
"{",
"response",
",",
"err",
":=",
"s",
".",
"RequestWithBucketID",
"(",
"\"",
"\"",
",",
"EndpointGatewayBot",
",",
"nil",
"... | // GatewayBot returns the websocket Gateway address and the recommended number of shards | [
"GatewayBot",
"returns",
"the",
"websocket",
"Gateway",
"address",
"and",
"the",
"recommended",
"number",
"of",
"shards"
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/restapi.go#L1898-L1917 | train |
bwmarrin/discordgo | restapi.go | RelationshipsMutualGet | func (s *Session) RelationshipsMutualGet(userID string) (mf []*User, err error) {
body, err := s.RequestWithBucketID("GET", EndpointRelationshipsMutual(userID), nil, EndpointRelationshipsMutual(userID))
if err != nil {
return
}
err = unmarshal(body, &mf)
return
} | go | func (s *Session) RelationshipsMutualGet(userID string) (mf []*User, err error) {
body, err := s.RequestWithBucketID("GET", EndpointRelationshipsMutual(userID), nil, EndpointRelationshipsMutual(userID))
if err != nil {
return
}
err = unmarshal(body, &mf)
return
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"RelationshipsMutualGet",
"(",
"userID",
"string",
")",
"(",
"mf",
"[",
"]",
"*",
"User",
",",
"err",
"error",
")",
"{",
"body",
",",
"err",
":=",
"s",
".",
"RequestWithBucketID",
"(",
"\"",
"\"",
",",
"Endpoint... | // RelationshipsMutualGet returns an array of all the users both @me and the given user is friends with.
// userID: ID of the user. | [
"RelationshipsMutualGet",
"returns",
"an",
"array",
"of",
"all",
"the",
"users",
"both"
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/restapi.go#L2212-L2220 | train |
bwmarrin/discordgo | eventhandlers.go | Handle | func (eh channelCreateEventHandler) Handle(s *Session, i interface{}) {
if t, ok := i.(*ChannelCreate); ok {
eh(s, t)
}
} | go | func (eh channelCreateEventHandler) Handle(s *Session, i interface{}) {
if t, ok := i.(*ChannelCreate); ok {
eh(s, t)
}
} | [
"func",
"(",
"eh",
"channelCreateEventHandler",
")",
"Handle",
"(",
"s",
"*",
"Session",
",",
"i",
"interface",
"{",
"}",
")",
"{",
"if",
"t",
",",
"ok",
":=",
"i",
".",
"(",
"*",
"ChannelCreate",
")",
";",
"ok",
"{",
"eh",
"(",
"s",
",",
"t",
... | // Handle is the handler for ChannelCreate events. | [
"Handle",
"is",
"the",
"handler",
"for",
"ChannelCreate",
"events",
"."
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L70-L74 | train |
bwmarrin/discordgo | eventhandlers.go | Handle | func (eh channelDeleteEventHandler) Handle(s *Session, i interface{}) {
if t, ok := i.(*ChannelDelete); ok {
eh(s, t)
}
} | go | func (eh channelDeleteEventHandler) Handle(s *Session, i interface{}) {
if t, ok := i.(*ChannelDelete); ok {
eh(s, t)
}
} | [
"func",
"(",
"eh",
"channelDeleteEventHandler",
")",
"Handle",
"(",
"s",
"*",
"Session",
",",
"i",
"interface",
"{",
"}",
")",
"{",
"if",
"t",
",",
"ok",
":=",
"i",
".",
"(",
"*",
"ChannelDelete",
")",
";",
"ok",
"{",
"eh",
"(",
"s",
",",
"t",
... | // Handle is the handler for ChannelDelete events. | [
"Handle",
"is",
"the",
"handler",
"for",
"ChannelDelete",
"events",
"."
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L90-L94 | train |
bwmarrin/discordgo | eventhandlers.go | Handle | func (eh channelPinsUpdateEventHandler) Handle(s *Session, i interface{}) {
if t, ok := i.(*ChannelPinsUpdate); ok {
eh(s, t)
}
} | go | func (eh channelPinsUpdateEventHandler) Handle(s *Session, i interface{}) {
if t, ok := i.(*ChannelPinsUpdate); ok {
eh(s, t)
}
} | [
"func",
"(",
"eh",
"channelPinsUpdateEventHandler",
")",
"Handle",
"(",
"s",
"*",
"Session",
",",
"i",
"interface",
"{",
"}",
")",
"{",
"if",
"t",
",",
"ok",
":=",
"i",
".",
"(",
"*",
"ChannelPinsUpdate",
")",
";",
"ok",
"{",
"eh",
"(",
"s",
",",
... | // Handle is the handler for ChannelPinsUpdate events. | [
"Handle",
"is",
"the",
"handler",
"for",
"ChannelPinsUpdate",
"events",
"."
] | 8325a6bf6dd6c91ed4040a1617b07287b8fb0eba | https://github.com/bwmarrin/discordgo/blob/8325a6bf6dd6c91ed4040a1617b07287b8fb0eba/eventhandlers.go#L110-L114 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.